2012-09-09 98 views
0

我有一个iframe,我试图根据它的实际内容调整它的大小(就像我没有得到任何滚动一样)。我试过以下内容:Firefox:根据实际内容调整iframe的大小

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

没有那些工作。 iframe包含iframe的ID。最后两行在Chrome中运行。

任何帮助将非常感激。

+0

这两个文档都在同一个域上吗? – tomsv

+0

Yeap - 同一个 – Yannis

+0

这个问题的重复? http://stackoverflow.com/questions/11806947/is-it-possible-that-iframe-resize-itself-without-help-from-main-window – Juffy

回答

0

我认为你不能从外部文档访问iframe中的文档属性,但是你可以用另一种方式来完成:从文档内部访问iframe中文档的属性,然后调用功能在外部文件中。这个外部函数然后会进行调整大小,如下所述:Resize iframe height according to content height in it

+0

当然,它应该以某种方式工作。它可以在Chrome中正常工作... – Yannis

+0

它是否可以在Firefox中使用? – tomsv

+0

不是那些我测试过的,我害怕.. – Yannis