auto re-sizing iframe that dynamically changing height (smaller or bigger)

前端 未结 2 1178
感情败类
感情败类 2021-01-16 20:39

I know there\'s a lot of post about re-sizing iframe but all i found is this code:



        
相关标签:
2条回答
  • 2021-01-16 20:55

    Why not just do:

    height: auto;
    max-height: 1200px;
    

    On the iframe itself within style="" or thru a css doc.

    If height is set to auto, then it won't need to use the 1200px for the index.php. But when displaying the profile.php it's allowed to use a maximum of 1200px.

    0 讨论(0)
  • 2021-01-16 21:05

    I reproduced the problem.

    The problem seems to be the use of scrollHeight and scrollWidth which by intention return the current or needed space of the scrollbar, which is not equal to the size of the document itself.

    The problem goes away for me when I change

     newheight = document.getElementById(id).contentWindow.document.body.scrollHeight;
     newwidth = document.getElementById(id).contentWindow.document.body.scrollWidth;
    

    into

     newheight = document.getElementById(id).contentWindow.document.body.style.height;
     newwidth = document.getElementById(id).contentWindow.document.body.style.width;
    

    is that doable for you, or is this not under your control?

    0 讨论(0)
提交回复
热议问题