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>

posted on 2017-09-29 15:43  改变从今天开始  阅读(286)  评论(0编辑  收藏  举报

导航