admin管理员组

文章数量:1318572

I have:

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

This function shows my body resolution in google chrome my (1350x651), in firefox (1509x20) and in internet explorer (nothing). Why are the resolution from different browser different?

thanks.

I have:

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

This function shows my body resolution in google chrome my (1350x651), in firefox (1509x20) and in internet explorer (nothing). Why are the resolution from different browser different?

thanks.

Share Improve this question asked Jan 1, 2012 at 11:27 KruegerKrueger 1,2283 gold badges13 silver badges27 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

With jQuery it's simple, do something like:

$(window).width();
$(document).width();
$(window).height();
$(document).height();

Without js this should suffice:

screen.height;
screen.width;

In your case im guessing you would use window since that's where you added the listener. Also, http://www.javascripter/faq/browserw.htm could help with some more foolproof code since offsetWidth and Height seems to be some IE thing.

You should use window.innerWidth and window.innerHeight

本文标签: javascriptBrowser39s screen resolutionStack Overflow