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

时间:2022-12-31 16:33:08
<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>