var a = parent.document.getElementsByTagName("IFRAME");
for (var i = 0; i < a.length; i++) {
// 是包含当前window的IFRAME,则调整高度
if (a[i].contentWindow == window) {
var h1 = 0, h2 = 0;
a[i].parentNode.style.height = a[i].offsetHeight + "px";
a[i].style.height = "10px"; //
if (document.documentElement && document.documentElement.scrollHeight) {
h1 = document.documentElement.scrollHeight;
}
if (document.body)
h2 = document.body.scrollHeight;
var h = Math.max(h1, h2); // 取两者中的较大值
if (document.all) {
h += 4;
}
if (window.opera) {
h += 1;
}
// 调整高度
a[i].style.height = a[i].parentNode.style.height = h + "px";
}
}
JS iframe高度自适应
最新推荐文章于 2022-08-23 20:11:06 发布