火狐iframe自适应高度以及bug

在火狐、IE中让iframe自适应高度的js函数,以及由于iframe页面css设置而引发的bug。
适合IE、火狐的自适应高度的JavaScript代码:
view plaincopy to clipboardprint?
function turnHeight(iframe)  
{  
    var frm = document.getElementById(iframe);  
    var subWeb = document.frames ? document.frames[iframe].document : frm.contentDocument;  
    if(frm != null && subWeb != null)  
    { frm.height = subWeb.body.scrollHeight + 20;}  

function turnHeight(iframe)
{
    var frm = document.getElementById(iframe);
    var subWeb = document.frames ? document.frames[iframe].document : frm.contentDocument;
    if(frm != null && subWeb != null)
    { frm.height = subWeb.body.scrollHeight + 20;}
}
调用方式:
view plaincopy to clipboardprint?
<IFRAME id=iframe1 onload="turnHeight('iframe1');" height="100%" src="framepage1.html" frameBorder=0 width="101%" scrolling=no></IFRAME> 

注意,iframe页面中的元素,不能使用float属性和display属性,否则在火狐中获取到的iframe高度将为0,导致自适应高度失败。
本文来源于 龙卷风资讯网 http://www.ljf.cn/ ;原文地址:http://www.ljf.cn/2010/2/Item231560.html


 

原文地址:https://www.cnblogs.com/aaa6818162/p/2317033.html