iframe高度自适应

来源:互联网 发布:淘宝网客户端mac 编辑:程序博客网 时间:2024/05/30 04:16

<iframe id="frame_content" name="frame_content" src="****.html"  allowTransparency="true"  style="width: 900px; " scrolling="no" frameborder="0" onload="this.height=100"></iframe>

<script type="text/javascript">

function reinitIframe(){

var iframe = document.getElementById("frame_content");

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){}

}

window.setInterval("reinitIframe()", 200);

</script>

原创粉丝点击