3

我想知道浏览器窗口的客户端大小。我使用简单的脚本:

wwidth  = window.innerWidth
wheight = window.innerHeight

但它不适用于 IE8、IE9。如何在所有形式的浏览器中使用 extjs 知道这个参数?

4

3 回答 3

14

如果你使用 Ext JS,你可以使用:

Ext.getBody().getViewSize()
于 2013-01-11T16:05:09.397 回答
1

这是纯 javascript 中的示例跨浏览器函数:

var getSize = function () {
    var winW = 0, winH = 0;
    if (document.body && document.body.offsetWidth) {
        winW = document.body.offsetWidth;
        winH = document.body.offsetHeight;
    }
    if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth ) {
        winW = document.documentElement.offsetWidth;
        winH = document.documentElement.offsetHeight;
    }
    if (window.innerWidth && window.innerHeight) {
        winW = window.innerWidth;
        winH = window.innerHeight;
    }   
    return { width: winW, height: winH };
};

window.onload = function(){
    alert(getSize().width);
};
于 2013-01-11T16:44:30.470 回答
0
function viewport(){
   var e = window , a = 'inner';
   if ( !( 'innerWidth' in window ) ) {
     a = 'client';
     e = document.documentElement || document.body;
   }
   return { width : e[ a+'Width' ] , height : e[ a+'Height' ] }
}
于 2014-03-31T13:10:59.440 回答