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>

上一篇:js基于json的级联下拉框


下一篇:iframe跨域修改子页面内容或样式