iframe自动适应内容的高度

方法一:

<script>
function autoResize()
{
try
{
document.all["mainFrame"].style.height=mainFrame.document.body.scrollHeight
}
catch(e){}
}
</script>
<iframe name="mainFrame" src="/ads/?ad=google&ad2=biz2008" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" width="100%" style="height:expression(1); aho:expression(autoResize())"></iframe>

方法二:

<iframe src="comment.jsp"  id="mainFrame" name="mainFrame" style="margin:20px 0;width:95%;height:600px;"  border="0" frameborder="0"  marginwidth="0" marginheight="0" allowtransparency="yes" ></iframe>

 

  <script>
    function iframeResize()
     {
      var dyniframe = document.getElementById("mainFrame");


      if (dyniframe) {
       if (dyniframe.contentDocument)
       {
        dyniframe.style.height = dyniframe.contentDocument.body.scrollHeight + 10;
       }
       else if (dyniframe.document && dyniframe.document.body.scrollHeight)
       {
        iframeheight = mainFrame.document.body.scrollHeight + 10;
        dyniframe.style.height = iframeheight;
       }
      }
     }

     function scroll_to_top()
     {
      document.body.scrollTop=0;
     }

     if (window.addEventListener)
      window.addEventListener("load", iframeResize, false);
     else if (window.attachEvent)
      window.attachEvent("onload", iframeResize);
     else
      window.onload = iframeResize;
     </script>

 

网页在最上面:

<script language="javascript">if(self!=top){top.location=self.location;};self.moveTo(0,0);self.resizeTo(screen.availWidth,screen.availHeight); </script>

你可能感兴趣的:(iframe自动适应内容的高度)