JavaScript screen.height and screen.width returns incorrect values

height, javascript, screen, width

Solution

Firefox returns a value based on the zoom percentage; however the window.devicePixelRatio gives you this percentage. Therefore the following JS code gives the correct values:

var w = screen.width; var h = screen.height;
var DPR = window.devicePixelRatio;
w = Math.round(DPR * w);
h = Math.round(DPR * h);

Problem

I want to get screen resolution of user display from JS, so i decide to use screen.height and screen.width properties, but i noticed that i got some incorrect values, f.e. i have full hd display with 1280 pixels in height but screen.height returns 630, and width 1120. What can cause that? Thanks! Edit: it seems it happens on FireFox for me, from IE 10 i got correct values.

Original source

Related problems