Iframe自适应其加载的内容高度
Iframe自适应其加载的内容高度
发布时间:2016-12-29 来源:查字典编辑
摘要:iframe自适应加载的页面高度child.htm:iframe自适应其加载的网页(多浏览器兼容)functioniframeAutoFit...

<html>

<head>

<metahttp-equiv='Content-Type'content='text/html;charset=gb2312'>

<metaname='author'content='站长中国http://www.zzcn.net/'>

<title>iframe自适应加载的页面高度</title>

</head>

<body>

<iframesrc="child.htm"></iframe>

</body>

</html>

child.htm:

<html>

<head>

<metahttp-equiv='Content-Type'content='text/html;charset=gb2312'>

<metaname='author'content='站长中国http://www.zzcn.net/'>

<title>iframe自适应其加载的网页(多浏览器兼容)</title>

<scriptlanguage=javascript>

functioniframeAutoFit()

{

try

{

if(window!=parent)

{

vara=parent.document.getElementsByTagName("IFRAME");

for(vari=0;i<a.length;i++)//author:meizz

{

if(a[i].contentWindow==window)

{

varh=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);

elsewindow.addEventListener('load',iframeAutoFit,false);

</script>

</head>

<body>

<divstyle="width:200;height:400;background-color:yellow">

iframe自适应其加载的网页(多浏览器兼容)

</div>

</body>

</html>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新 Div+Css教程学习
热门 Div+Css教程学习
网页设计子分类