如何从IE中的跨域iframe获取窗口大小 [英] How to get window size from cross-domain iframe in IE

查看:97
本文介绍了如何从IE中的跨域iframe获取窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在跨域方案中,我需要知道在iframe内运行的javascript代码时iframe大小(宽度和高度)中的内容。 (我不能爬到父母,因为我在跨域iframe)
注意:我不想使用jquery。
我尝试了几种获取信息的方法:

In a cross domain scenario I need to know what's in the iframe size (width and height) when the javascript code running inside the iframe. (I can't climb to the parent because I'm in a cross domain iframe) Note: I don't want to use jquery. I tried several ways to get that info:

var w = window.innerWidth || window.document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth || document.body.offsetWidth
var h = window.innerHeight || window.document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight || document.body.offsetHeight


推荐答案

如果你想得到窗口大小,使用此项(如果有,则不包括滚动条大小):

If you want to get the window size, use this(excluding the scrollbar size if there is):

var w = document.documentElement.clientWidth;
var h = document.documentElement.clientHeight;

如果要获取文档大小,请使用此项(如果有,则不包括滚动条大小):

If you want to get the document size, use this(excluding the scrollbar size if there is):

var w = document.documentElement.scrollWidth;
var h = document.documentElement.scrollHeight;

这篇关于如何从IE中的跨域iframe获取窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆