search

Home  >  Q&A  >  body text

javascript - iframe height adaptive problem

The following is the content of the main page:

        <script type="text/javascript">
            function changeFrameHeight(){
                var ifm= document.getElementById("iframepage");
                ifm.height=document.body.clientHeight + 50;
            }
            window.onresize=function(){  
                 changeFrameHeight();
            } 
        </script>
        <p id="tt">
            <p title="首页">
                <iframe src="page/home.html" id="iframepage"  onload="changeFrameHeight()"  style="width:100%;" scrolling="no" frameborder="0"></iframe>
            </p>
        </p>

When the page is zoomed out, all the contents of home.html cannot be displayed. How should I change it?

阿神阿神2785 days ago593

reply all(2)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-19 10:40:27

    <script type="text/javascript">

    function changeFrameHeight(){
      setTimeout(function(){
        var iFrameID = document.getElementById('iframepage');
        if(iFrameID) {
          iFrameID.height = "";
          iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
        }   
      },300)
    }
    window.onresize=function(){  
      changeFrameHeight();
    } 

    </script>

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-19 10:40:27

    Then you have to write the adaptation of the window size in the home page

    reply
    0
  • Cancelreply