JS获取IFRAME内容高度

var ifr = this.create("iframe");//自定义创建IFRAME的方法
ifr.src = "HTMLPage.htm";

if (ifr.attachEvent) {//IE
ifr.attachEvent("onload", function() {
setTimeout(function() { ifr.css({ height: ifr.contentWindow.document.body.scrollHeight + 'px' }); }, 100);
});
} else {
ifr.onload = function() {
setTimeout(function() {
ifr.css({ height: ifr.contentWindow.document.body.scrollHeight + 'px' });//自定义的方法
}, 100);
}
}
ifr.appendTo(document.body);//自定义的方法,将IFRAME添加到页面

以上是案例,创建了IFRAME,并设置IFRAME的高度

获取高度:document.getElementById('Iframe的ID').contentWindow.document.body.scrollHeight;

原文地址:https://www.cnblogs.com/554006164/p/2323377.html