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