遍历元素来确定iframe的高度

This commit is contained in:
fofolee 2022-06-05 10:00:24 +08:00
parent 827cd193a2
commit 2008b0b007

View File

@ -86,7 +86,12 @@ export default {
!utools.isDarkColors() || (cfw.document.body.style.color = "white");
let clientHeight =
cfw.document.documentElement.getBoundingClientRect().height;
this.frameHeight = clientHeight === 20 ? 0 : clientHeight;
clientHeight = clientHeight === 20 ? 0 : clientHeight;
this.frameHeight = Math.max(
//
this.getMaxElHeight(cfw.document),
clientHeight
);
this.$emit("frameLoad", this.frameHeight);
};
},
@ -108,6 +113,14 @@ export default {
onerror: (e) => showError(e),
};
},
getMaxElHeight(doc) {
let els = Array.prototype.slice.call(doc.body.getElementsByTagName("*"));
let elHeights = [];
for (let i = 0, l = els.length; i < l; i++) {
elHeights.push(els[i].scrollTop + els[i].offsetHeight);
}
return Math.max.apply(Math, elHeights);
},
},
};
</script>