任何人都可以建议如何确定即7/8的当前窗口大小,或者通常我需要计算当前宽度以便重定向到iframe到目前为止我已经尝试过:
document.documentElement.offsetWidth - 仅适用于ie9
document.body.offsetWidth - undefined
self.innerWidth - undefined
也许任何人都可以建议原型方法?
谢谢你们!
if(document.documentElement.offsetWidth > (old_w + new_w)){
window.location = '/mylocation';
}
答案 0 :(得分:2)
试试这个......正如我所研究的那样,这是一个跨浏览器实现你正在寻找的东西:
window.$getView = function() {
var ret = {
width : 0,
height : 0,
element : null
};
if( typeof window.innerWidth != 'undefined') {
ret.width = window.innerWidth;
ret.height = window.innerHeight;
ret.element = window;
} else if( typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
ret.width = document.documentElement.clientWidth;
ret.height = document.documentElement.clientHeight;
ret.element = document.documentElement;
} else {
ret.width = document.getElementsByTagName('body')[0].clientWidth;
ret.height = document.getElementsByTagName('body')[0].clientHeight;
ret.element = document.getElementsByTagName('body')[0];
}
return ret;
}