父页面iframe自动适应子页面的宽高度

<script type="text/javascript">
   function load(){
     parent.document.getElementById("myiframe").style.height = document.body.scrollHeight +"px";
     parent.document.getElementById("myiframe").style.width = document.body.scrollWidth +"px";
   }
</script>

<body onLoad="load();">


<iframe name="main" src="#" frameborder="0" scrolling="no" style="min-width:750px;" scrolling="auto" id="iframeh"></iframe>
<script type="text/javascript">
function reinitIframe(){var iframe = document.getElementById("iframeh");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>

 

posted @ 2013-06-20 11:52  Liu66~  阅读(638)  评论(0编辑  收藏  举报