脚本宝典收集整理的这篇文章主要介绍了Iframe自适应其加载的内容高度,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<ht
ML>&nbs
p; <head>
<
;meta http-equiv='Content
-ty
PE' content='text/html; charset=gb2312'>
<meta n
ame='author' content='
站长中国 http://www.zzcn.net/'>
<t
ITle>iframe自适应加载的页面高度</title>
</head>
<body>
<iframe src="child.htm"></iframe>
</body>
</html>
child.htm:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='站长中国 http://www.zzcn.net/'>
<title>iframe 自适应其加载的网页(多浏览器兼容)</title>
<script language=javascript>
function iframeAutoFit()
{
try
{
if(window!=parent)
{
VAR a = parent.document.
getelementsbytagname("IFRAME");
for(var i=0; i<a.length;
i++) //author:m
eizz
{
if(a[i].contentWindow
==window)
{
var h = document.body.scrollHeight;
if(document.all) {h += 4;}
if(window.
opera) {h += 1;}
a[i].style.height = h;
}
}
}
}
catch (ex)
{
alert("脚本无法跨域操作!");
}
}
if(document.attachEvent) window.attachEvent("onload", iframeAutoFit);
else window.addEventListener('load', iframeAutoFit, false);
</script>
</head>
<body>
<div style="width: 200; height: 400; background-color: yellow">
iframe 自适应其加载的网页(多浏览器兼容)
</div>
</body>
</html>
脚本宝典总结
以上是脚本宝典为你收集整理的Iframe自适应其加载的内容高度全部内容,希望文章能够帮你解决Iframe自适应其加载的内容高度所遇到的问题。
如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。