gpt4 book ai didi

javascript - 从 iframe 内部检测 <iframe> 高度和宽度

转载 作者:技术小花猫 更新时间:2023-10-29 12:40:47 25 4
gpt4 key购买 nike

我怀疑这是否真的可行,但我准备接受纠正。

我需要的是能够从 iframe 中检测 iframe 的宽度和高度,所以如果 iframe srciframeContent.html 我需要能够在此页面上显示值。

我无法控制托管 iframe 的页面,只能控制 iframe 的内容。

这可能吗?

最佳答案

无论页面是否加载到 iframe 中,您始终可以获得网页尺寸。或一个新窗口,它始终以相同的方式工作。这是我发现用于获取 window 的函数尺寸,你也可以用它来获得 <iframe>维度。

function alertSize() {
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
window.alert( 'Width = ' + myWidth );
window.alert( 'Height = ' + myHeight );
}

关于javascript - 从 iframe 内部检测 &lt;iframe&gt; 高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7808729/

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