<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title>a</title>
</head>
<body>
<div style="border:1px dotted;width:400px">
<iframe id="child" src="child.html" scrolling="no" frameborder="0" onload="this.height=100"></iframe>
</div>
<script type="text/javascript">
function reinitIframe(){
var iframe = document.getElementById("child");
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){
}
}
/*
定时调整大小,
比如按钮触发div的显示可能会引起页面高度的变化,
需要实时调整
*/
window.setInterval("reinitIframe()", 200);
</script>
</body>
</html>
iframe 自适应高度
最新推荐文章于 2009-12-10 18:15:04 发布