父页面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-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>
原文地址:https://www.cnblogs.com/liuswi/p/3145714.html