镶入网页自动延伸大小,高度保持镶入网页的高度

平时我们或许会在一个网页中镶入一个可以不固定高度的网页,我们需要让框架随着镶入网页的高度从而增加高度,以下代码可以解决不支持自动扩展高度的问题。
 
<div class="g-doc" style="margin-top:0px;">
<iframe id="c-c-iframe" name="xxx" src="dh.htm" frameBorder="0" width="100%" scrolling="no"></iframe>
</div>
<script type="text/javascript">
function reinitIframe(){
var iframe = document.getElementById("c-c-iframe");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
//var height = Math.max(bHeight, dHeight);
var height = Math.min(bHeight, dHeight);
iframe.height = height;
}catch (ex){}
}
window.setInterval("reinitIframe()", 0);
</script>

1 个评论

要回复文章请先登录注册