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;

posted @ 2012-01-16 10:59  瞭望者  阅读(3859)  评论(2编辑  收藏  举报