How to get window size from cross-domain iframe in IE

半城伤御伤魂 提交于 2019-12-23 01:36:18

问题


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

回答1:


So, are you trying to access an iframe on another domain? You can't, because of XSS protection.

Here's a similar question: Get DOM content of cross-domain iframe

http://en.wikipedia.org/wiki/Cross-site_scripting

EDIT: Maybe this solution could give you an hint on what to do http://paulasmuth.com/blog/dynamic_height_crossdomain_iframe/ depending on the permissions you have on your pages.




回答2:


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;


来源:https://stackoverflow.com/questions/13798540/how-to-get-window-size-from-cross-domain-iframe-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!