浏览器的屏幕分辨率?

Kru*_*ger 2 javascript screen-resolution

我有:

window.addEventListener('resize',doSomething,false);
        function doSomething() {
            var yres = document.body.offsetHeight;
            var xres = document.body.offsetWidth;
            alert(xres+'x'+yres);
        }
Run Code Online (Sandbox Code Playgroud)

此功能在google chrome my(1350x651),firefox(1509x20)和Internet Explorer(无)中显示我的身体分辨率.为什么不同浏览器的分辨率不同?

谢谢.

lfx*_*ove 5

使用jQuery很简单,执行以下操作:

$(window).width();
$(document).width();
$(window).height();
$(document).height();
Run Code Online (Sandbox Code Playgroud)

没有js这应该足够了:

screen.height;
screen.width;
Run Code Online (Sandbox Code Playgroud)

在你的情况下我猜你会使用窗口,因为那是你添加监听器的地方.此外,http://www.javascripter.net/faq/browserw.htm可以帮助一些更简单的代码,因为offsetWidth和Height似乎是一些IE的东西.