<iframe name="ifrm" id="frm" src="yourPage.asp"><iframe>
<button onclick="frm.style.height=document.ifrm.document.body.clientHeight">
让iframe高度适应其内叶面高度</button>
--------------------------------------------------------------- 1.htm的代码:
<iframe src=2.htm id=ifrm></iframe>
2.htm的代码:
<script>
function resize()
{parent.document.all.ifrm.height=document.body.scrollHeight;}
</script>
<body onload="resize()">
</body>
用iframe模拟frame子页.htm
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'>
<title>iframe 自适应其加载的网页(多浏览器兼容)</title>
<script language=javascript>
function iframeAutoFit() //author: meizz(梅花雪 20041225)
{
if(self!=top && window.name=="MzMain") //这个 name 对应的是 iframe 的 name
{
var iframe = parent.document.getElementById(window.name);
if(iframe)
{
iframe.parentNode.style.height = iframe.style.height;
iframe.style.height = 10;
var h = document.body.scrollHeight;
var minimalHeight = parseInt((window.screen.width*11)/16, 10) - 280;
h = h<minimalHeight ? minimalHeight : h;
if(window.navigator.appName == "Microsoft Internet Explorer"
&& iframe.frameBorder=="1") h += 4;
iframe.parentNode.style.height = iframe.style.height = h;
}
else alert("Iframe's id unequal to iframe's name!");
}
}
if(document.attachEvent) window.attachEvent("onload", iframeAutoFit);
else window.addEventListener('load', iframeAutoFit, false);
</script>
</head>
<body>
<span style="width: 300; height: 400; background-color: yellow">
iframe 自适应其加载的网页(多浏览器兼容)
</span>
</body>
</html>
posted on 2006-04-03 15:30
汪杰 阅读(252)
评论(0) 编辑 收藏 引用 所属分类:
javascript 、
hengxing网站js