iframe 自适应高度[在IE6 IE7 FF下测试通过]
更新时间:2009年04月13日 10:41:45 作者:
有时候我们需要让我们的iframe自动适应高度,但多浏览器兼容性不好,大家不妨试下这个。
第一种方法:
<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>
复制代码 代码如下:
<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 操作table,可以新增行和列并且隔一行换背景色代码分享
这篇文章介绍了JavaScript操作table,可以新增行和列并且隔一行换背景色代码,有需要的朋友可以参考一下2013-07-07
JavaScript 使用Ckeditor+Ckfinder文件上传案例详解
这篇文章主要介绍了JavaScript 使用Ckeditor+Ckfinder文件上传案例详解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下2021-08-08


最新评论