先附上代码,详细查看注释部分.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>iframe自适应高度</title>
<script type="text/javascript">
window.onload = (function () {
var iObj = document.getElementById('iframeDiv'); //iframe 的ID号
iObj.height = iObj.contentWindow.document.documentElement.scrollHeight; //contentWindow iframe的属性
});
</script>
</head>
<body>
<p>http://www.51jquery.com/2009-09/iframe-autoheight/</p>
<p>http://ued.koubei.com/?p=243</p>
<h2> iframe自适应</h2>
<p>1.如果 iframe 里面无许做 DOM 操作的话,我们可以在iframe里面直接 加一个事件 <pre>onload="this.height=this.contentWindow.document.documentElement.scrollHeight" </pre></p>
<p>2.利用 iframe 的ID号 获取 iframe子页面的 contentWindow</p>
<p>3.在iframe页里进行DOM操作,或者表格展现(表格展现如果挤压会改变高度)可以使用下面的方法:</p>
<pre>
<code><script type="text/javascript">
function reinitIframe() {
var iframe = document.getElementById("iframe");
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) { }
}
window.setInterval("reinitIframe()", 200); //定时去检查iframe的高度,这样保证时时都是自动高了
</script>
</code>
</pre>
<div class="iframe" id="iframe" >
<iframe frameborder="1" scrolling="no" src="test1.html" name="iframe" id="iframeDiv" width="100%" height="100%">
</iframe>
</div>
</body>
</html>
分享到:
相关推荐
这个库允许的高度与同跨域iframe来适应他们所包含的内容的宽度自动调整大小。它最常见的问题与使用iframes提供一系列的功能,其中包括: 高度和宽度大小的iframe内容大小。 作品以多个嵌套的iframe。 跨域iframe域...
iframe 自适应高度iframe 自适应高度iframe 自适应高度iframe 自适应高度iframe 自适应高度iframe 自适应高度iframe 自适应高度iframe 自适应高度
iframe自适应高度和宽度
iframe自适应高度说明文档iframe自适应高度说明文档iframe自适应高度说明文档iframe自适应高度说明文档iframe自适应高度说明文档iframe自适应高度说明文档iframe自适应高度说明文档iframe自适应高度说明文档iframe...
纯JS实现的iframe自适应高度。兼容主流浏览器。
iframe自适应高度(兼容多种浏览器) 亲测可以
Iframe自动根据类容改变自己的大小,解决Iframe设置高度后无法缩小!拜一个高人所赐,特表示感谢!
jquery对iframe自适应高度插件是国外下载下来的。插件使用只要引用js文件就行,不用做任何别的操作完全自动化。
多层嵌套iframe 自适应高度的解决方法
因为有一个项目要用到iframe自适应高度,网上搜索了以下结果无数,不过看来看去都是那几个,而且基本都测试了一遍,所说的兼容根本不是那么回事,要不IE不正常,要不其他浏览器显示不正常,最后无奈,综合网上的方法...
IFRAME 自适应 页面布局 自适应高度
javascript iframe 自适应高度js demo
iframe自适应高度
iframe自适应高度 .txtiframe自适应高度 .txtiframe自适应高度 .txtiframe自适应高度 .txtiframe自适应高度 .txt
iframe自适应高度的简单解决办法,word文档中有详细的解释,赶快下载吧!
iframe自适应高度 .doc
介绍: 填写的嵌入地址一定要和本页面在同一个站点上,否则会提示“拒绝访问!”。对跨域引用有权限问题,请查阅其他资料。
iframe自适应高度(DOM动态操作)
iframe包含的页面的高度,兼容性好,iframe高度自适应
iframe 跨域 自适应高度 模板 iframe 跨域 自适应高度 模板 iframe 跨域 自适应高度 模板