【发布时间】:2010-10-10 09:52:55
【问题描述】:
如何使用 Javascript 检测用户窗口的宽度并考虑他们的滚动条? (我需要滚动条内的屏幕宽度)。这就是我所拥有的......它似乎可以在多个浏览器中工作......除了它不考虑滚动条......
function browserWidth() {
var myWidth = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
} else if( document.documentElement && document.documentElement.clientWidth ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
} else if( document.body && document.body.clientWidth ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
}
return myWidth;
}
有什么想法吗?我需要它在所有浏览器中工作;)
【问题讨论】:
标签: javascript screen width