指各位高手指点出我在iframe下面写的js代码在firefox浏览器不起作用,是什么问题呢?
JS如下:
function SetCwinHeight()

var cwin=document.getElementById("cwin");
if (document.getElementById)
{  
if (cwin && !window.opera)
{   
if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
cwin.height = cwin.contentWindow.body.offsetHeight;
else if(cwin.Document && cwin.Document.body.scrollHeight)
//cwin.height = cwin.Document.body.scrollHeight;  
                cwin.style.height = cwin.contentWindow.document.body.scrollHeight + 20 + "px"; 
}
}
}
iframe如下:
<iframe  frameBorder=0 width="100%" scrolling=no height=420 id="cwin" name="cwin" src="index.php?controller=review_write&product_id=<?php echo $product_id; ?>"   onLoad="Javascript:SetCwinHeight()" ></iframe>

解决方案 »

  1.   


    <IFRAME id=iframe1 src="/main/sf.php" frameBorder=0 width="986" scrolling=no onload="turnHeight('iframe1');" height="100%"></IFRAME>  simple'blog
    function turnHeight(iframe)   
    {   
        var frm = document.getElementById(iframe);   simple'blog
        var subWeb = document.frames ? document.frames[iframe].document : frm.contentDocument;   
        if(frm != null && subWeb != null)   
        { frm.height = subWeb.body.scrollHeight + 20;}   

    下面的js 调用上面的iframe,是ie和火狐都兼容的,看看你有没有帮助,我觉的就是你加了“px”的问题。 注意,iframe页面中的元素,不能使用float属性和display属性,否则在火狐中获取到的iframe高度将为0,导致自适应高度失败。