iframe resizing with scrollheight in chrome/safari

后端 未结 3 2033
情歌与酒
情歌与酒 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.

提交回复
热议问题