iframe resizing with scrollheight in chrome/safari

后端 未结 3 1987
情歌与酒
情歌与酒 2020-12-01 11:06

I\'m trying to resize (make bigger or smaller) an iframe based on it\'s contents. After a click on each page a method is called which does the resizing.

In Chrome I

相关标签:
3条回答
  • 2020-12-01 11:27

    Before you ask for the height of the document inside the iframe you should set the height of the iframe object to "auto". Something like this:

    objIframe = document.getElementById('theIframeId');    
    objIframe.style.height = 'auto';
    

    And now:

    document.body.scrollHeight
    

    returns the actual height of the document.

    0 讨论(0)
  • 2020-12-01 11:30

    According to spec, Element.scrollHeight will round the value to an integer. If you need an accurate fractional value, use Element.getBoundingClientRect() instead.

    0 讨论(0)
  • 2020-12-01 11:39

    Did you try using document.documentElement.scrollHeight instead?

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