简体   繁体   中英

Browser's screen resolution?

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.

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.net/faq/browserw.htm could help with some more foolproof code since offsetWidth and Height seems to be some IE thing.

您应该使用window.innerWidthwindow.innerHeight

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM