gpt4 book ai didi

javascript - 动态设置 iframe 高度;不适用于 ie 和 chrome

转载 作者:行者123 更新时间:2023-11-30 18:33:02 25 4
gpt4 key购买 nike

我正在尝试使用 javascript 和 Jquery 动态设置 iframe 的高度。

但出于某种原因,这在 Ie8 和 chrome 中不起作用。 (但它在 firefox 上运行良好)

有人可以帮忙吗?

谢谢

 function resizePanel() {
window.console.log("ran the resize panel function");
var frame = document.getElementsByTagName('iframe')[0];
if(frame != null) {

var height;
if(self.innerHeight) {
window.console.log("ran the self.innerHeight");
height= self.innerHeight;
}
else if (document.documentElement && (document.documentElement.clientHeight)) {
window.console.log("ran the clientHeight");
height = document.documentElement.clientHeight;
}
else if(document.body) {
window.console.log("ran the document.body");
height = document.body.clientHeight;
}
frame.style.height = height - 165 + 'px'
}};

$(document).ready(function() {
resizePanel();
$(window).resize(function() {
resizePanel();
});
});

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(EndRequest);

function EndRequest(sender, args) {
resizePanel();
}

最佳答案

您的代码似乎有点复杂,您可以执行以下操作:

function resizePanel() {
window.console.log("ran the resize panel function");
var frame = document.getElementsByTagName('iframe')[0];
if(frame != null) {
frame.style.height = frame.contentWindow.document.body.scrollHeight + "px";
}
}

应该适用于所有主流浏览器。

关于javascript - 动态设置 iframe 高度;不适用于 ie 和 chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9066181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com