简体   繁体   English

Firefox:根据实际内容调整iframe的大小

[英]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). 我有一个iframe,我正在尝试根据其实际内容调整大小(例如,这样我就不会滚动)。 I have tried the following: 我尝试了以下方法:

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

None of those work. 这些都不起作用。 iframe contains the id of the iframe. iframe包含iframe的ID。 The last two lines work in Chrome. 最后两行适用于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. 我认为您无法从外部文档访问iframe中文档的属性,但可以通过另一种方式进行操作:从该文档本身内部访问iframe中文档的属性,然后在外部调用函数文献。 This outside function would then do the resizing, as described here: Resize iframe height according to content height in it 然后,此外部函数将进行大小调整,如下所述: 根据其中的内容高度调整iframe的高度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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