代码如下
// 浏览器窗口的宽度,兼容 Internet Explorer 8, 7, 6, 5
function getClientWidth(){
return window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;
}
// 浏览器窗口的高度,兼容 Internet Explorer 8, 7, 6, 5
function getClientHeight(){
return window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
}
console.log(getClientWidth());
console.log(getClientHeight());
参考 JavaScript Window - 浏览器对象模型