From 2008b0b00759717adf67ccc004a72cd1feda9a5a Mon Sep 17 00:00:00 2001 From: fofolee Date: Sun, 5 Jun 2022 10:00:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=8D=E5=8E=86=E5=85=83=E7=B4=A0=E6=9D=A5?= =?UTF-8?q?=E7=A1=AE=E5=AE=9Aiframe=E7=9A=84=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ResultArea.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/ResultArea.vue b/src/components/ResultArea.vue index 1cb841b..7bbc178 100644 --- a/src/components/ResultArea.vue +++ b/src/components/ResultArea.vue @@ -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); + }, }, };