[英]Detect <iframe> height and width from inside the iframe
我怀疑这实际上是可能的,但我准备纠正。
我需要的是能够从iframe中检测iframe的宽度和高度,所以如果iframe src
是iframeContent.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 );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.