Why does the iframe function define different values each time?



  • The following function shall be performed onload at iframe in order to extend iframe to the height corresponding to its contents and to rid itself of the lane.

    Function code:

    function resizeIframe(iframe) { let elem = document.getElementById('myFrame'); let size=elem.contentWindow.document.body.scrollHeight; elem.style.height = size + "px"; }

    During each download of the iframe page, the iframe height shall be different. The contents of the page loaded in iframe are consistent with the width of the browser window. Why is there always a different height at the iframe and how do you fight it?



  • You're probably not the only one who does the code onload. So if some data haven't come in yet, you've got one height, and if you've painted it, the other one.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2