4

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.

4

1 回答 1

7

Firefox 根据缩放百分比返回一个值;但是 window.devicePixelRatio 会给你这个百分比。因此,以下 JS 代码给出了正确的值:

var w = screen.width; var h = screen.height;
var DPR = window.devicePixelRatio;
w = Math.round(DPR * w);
h = Math.round(DPR * h);
于 2017-06-29T18:07:31.750 回答