iframe 自适应高度[在IE6 IE7 FF下测试通过]

2019-12-25,,,

第一种方法:
复制代码 代码如下:
<script type="text/javascript" language="javascript">
<!--
//调整 PageContent 的高度
function TuneHeight() {
var frm = document.getElementById("content01");
var subWeb = document.frames ? document.frames["content01"].document : frm.contentDocument;
if(frm != null && subWeb != null) {
frm.height = subWeb.body.scrollHeight;
}
}
//-->
</script>

<iframe id="content01" name="content01" frameBorder=0 scrolling=no src="main.html" width="100%"onLoad="TuneHeight()" ></iframe>

第二种方法:
js code:
复制代码 代码如下:
//iframe自适应高度[在IE6 IE7下测试通过]
function reSetIframe(){
var iframe = document.getElementById("iframeId");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}catch (ex){}
}

html:
复制代码 代码如下:
<iframe src="" id="weather" name="weather" width="278" onload="reSetIframe()" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" border="0" framespacing="0"> </iframe>

您可能感兴趣的文章:

  • 关于div自适应高度/左右高度自适应一致的js代码
  • Iframe自适应高度绝对好使的代码 兼容IE,遨游,火狐
  • Iframe 自适应高度并实时监控高度变化的js代码
  • javascript 装载iframe子页面,自适应高度
  • iframe自适应高度的多种方法方法小结
  • Iframe自适应高度兼容ie,firefox多浏览器
  • 让iframe自适应高度(支持XHTML,支持FF)
  • 让iframe自适应高度(支持xhtml)IE firefox兼容
  • [转]目前找到的最好的Iframe自适应高度代码
  • 关于IFRAME 自适应高度的研究
  • JavaScript 处理Iframe自适应高度(同或不同域名下)

《iframe 自适应高度[在IE6 IE7 FF下测试通过].doc》

下载本文的Word格式文档,以方便收藏与打印。