第一种方法:复制代码 代码如下:<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>
推荐阅读
JavaScript 学习点滴记录
通过使用 getElementById() 和 getElementsByTagName() 方法 通过使用一个元素节点的 parentNode、firstChild 以及 lastChild 属性 有两种特殊的文档属性可用来访问根节点: document.documentElement document.bo>>>详细阅读
本文标题:iframe 自适应高度[在IE6 IE7 FF下测试通过]
地址:http://www.17bianji.com/kaifa2/JS/28808.html
1/2 1