Iframe 父页面自动获取子页面的高度

<iframe id="mainweb" name="mainweb" src="http://www.baidu.com/" border="0" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="100%" target="_parent" onload="iFrameHeight()" ></iframe>

<script type="text/javascript" language="javascript">
function iFrameHeight()
{
   var ifm= document.getElementById("mainweb");
   var subWeb = document.frames ? document.frames["mainweb"].document : ifm.contentDocument;
   if(ifm != null && subWeb != null)
   {
      ifm.height = subWeb.body.scrollHeight;
   }
}
</script>

原文地址:https://www.cnblogs.com/enamorbreeze/p/7611354.html