You can retrieve the height of the IFRAME
's content by using: contentWindow.document.body.scrollHeight
(您可以使用以下方法检索IFRAME
内容的高度: contentWindow.document.body.scrollHeight
)
After the IFRAME
is loaded, you can then change the height by doing the following:(加载IFRAME
后,可以执行以下操作来更改高度:)
<script type="text/javascript">
function iframeLoaded() {
var iFrameID = document.getElementById('idIframe');
if(iFrameID) {
// here you can make the height, I delete it first, then I make it again
iFrameID.height = "";
iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
}
}
</script>
Then, on the IFRAME
tag, you hook up the handler like this:(然后,在IFRAME
标记上,像这样连接处理程序:)
<iframe id="idIframe" onload="iframeLoaded()" ...
I had a situation a while ago where I additionally needed to call iframeLoaded
from the IFRAME
itself after a form-submission occurred within.(不久前,我遇到了一种情况,即在其中发生表单提交后,我还需要从IFRAME
本身调用iframeLoaded
。) You can accomplish that by doing the following within the IFRAME
's content scripts:(您可以通过在IFRAME
的内容脚本中执行以下操作来实现:)
parent.iframeLoaded();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…