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;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM