Javascript 在IE上获取iframe内的身高

Javascript 在IE上获取iframe内的身高,javascript,Javascript,在iframe内部,我试图与父文档通信内容高度,以便调整iframe的大小。通信工作正常,问题在于获取内容高度。即使在加载DOM之后,给定的高度也是默认值,即30 px,而不是像5000px那样的实际高度。我只在IE8和IE9上遇到这个问题 我曾尝试使用window.onload事件,但没有调用它,因此我尝试创建一个每秒获取内容高度的循环,以查看它是否得到更新,但即使在加载了所有DOM之后,问题仍然存在 我有这样的想法: checkHeightLoop = setInterval(functio

在iframe内部,我试图与父文档通信内容高度,以便调整iframe的大小。通信工作正常,问题在于获取内容高度。即使在加载DOM之后,给定的高度也是默认值,即30 px,而不是像5000px那样的实际高度。我只在IE8和IE9上遇到这个问题

我曾尝试使用window.onload事件,但没有调用它,因此我尝试创建一个每秒获取内容高度的循环,以查看它是否得到更新,但即使在加载了所有DOM之后,问题仍然存在

我有这样的想法:

checkHeightLoop = setInterval(function(){resizeIframe()}, 1000);

function resizeIframe(){
  parent.postMessage("resizeIframe#" + $('body').outerHeight( true ), "*");
}
这个循环很愚蠢,但只是想看看即使在加载DOM之后我是否能得到不同的高度,因为没有调用event window.onload。除了获取内容高度的Jquery方法之外,我已经尝试过:

var x = window.innerHeight,
    y = window.scrollY,
    z = document.body.clientHeight,
    a = document.body.scrollHeight,
    b = document.body.offsetHeight,
    c = document.documentElement.clientHeight,
    d = document.documentElement.scrollHeight,
    e = document.documentElement.offsetHeight,

我需要查看你的全部代码才能得到一张图片,但是

你有没有试过使用这个工具。它在DOM之后激活

好的,在阅读了关于你的问题的更多内容之后。在父文档中尝试以下代码:

<script language="JavaScript">
function aResize(id)
{
    var nh;
    var nw;
        nh=document.getElementById(id).contentWindow.document .body.scrollHeight;
        nw=document.getElementById(id).contentWindow.document .body.scrollWidth;
        document.getElementById(id).height= (nh) + "px";
        document.getElementById(id).width= (nw) + "px";
}
</script>

<iframe src="yourpage.aspx" width="100%" height="100px" id="if1" frameborder="0" onLoad="aResize('if1');"></iframe>

函数大小(id)
{
var nh;
西北风;
nh=document.getElementById(id).contentWindow.document.body.scrollHeight;
nw=document.getElementById(id).contentWindow.document.body.scrollWidth;
document.getElementById(id).height=(nh)+“px”;
document.getElementById(id).width=(nw)+“px”;
}

谢谢你的回答,我用代码编辑了我的帖子。谢谢,因为家长在另一个域中,我能做document.getElementById(id).contentWindow.document.body.scrollHeight吗?