欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Resize iFrame height according to content 同域 高度自适应

I have a popup page which has an iframe which in turn loads another page.


I want to resize the iframe height depending on the size of page loaded in it.

    1 Answer 正确答案 

    one of the easy way is using javascript:

    <script language="JavaScript">
      function autoResize(id){
      var newheight;
      var newwidth;
    
      if(document.getElementById){
        newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
        newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
      }
    
      document.getElementById(id).height= (newheight) + "px";
      document.getElementById(id).width= (newwidth) + "px";
    }
    </script>
    
    <IFRAME SRC="Iframef/iframep.aspx" width="100%" height="200px" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');"></iframe>

    来自  https://stackoverflow.com/questions/11826649/resize-iframe-height-according-to-content


    普通分类: