简体   繁体   中英

Firefox: Resize iframe according to actual content

I have an iframe and I am trying to resize it based on its actual content (like so I dont get any scrolling). I have tried the following:

alert(document.getElementById(iframe).contentWindow.document.body.height); alert(document.getElementById(iframe).contentWindow.document.body.scrollHeight); alert(document.getElementById(iframe).contentWindow.document.body.offsetHeight);

None of those work. iframe contains the id of the iframe. The last two lines work in Chrome.

Any help would be really appreciated.

I think you cannot access the properties of the document in the iframe from the outside document, but you can do it the other way: access the properties of the document in the iframe from within that document itself, and then call a function in the outside document. This outside function would then do the resizing, as described here: Resize iframe height according to content height in it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM