站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Javascript 专题JavaScript应用:Iframe自适应其加载的内容高度

JavaScript应用:Iframe自适应其加载的内容高度

摘要: JavaScript应用:Iframe自适应其加载的内容高度
<textarea readonly style="border:none;font-family:Courier New;line-height:150%;width:760px;overflow-y:visible">

main.htm:


<head>


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

<body>
<iframe src="child.htm"></iframe>
</body>

child.htm:


<head>


iframe 自适应其加载的网页(多浏览器兼容)
<script language=javascript>
function iframeAutoFit()
{
try
{
if(window!=parent)
{
var a = parent.document.getElementsByTagName("IFRAME");
for(var i=0; i {
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>


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

</body>


</textarea>
↑返回目录
前一篇: 一个很好的日历控件(采用javascript编写)
后一篇: 用javascript 自动调节iframe高度出现问题