javascriptdomcssom

How to detect device's screen resolution on macbook?


It's said that to calculate screen real resolution I need to multiply screen.width by window.devicePixelRatio. The thing is on one of my laptops it works perfectly fine, window.screen.width = 1280, multiplying by pixel ratio (2) = 2560, which is correct according to system information.

But on my second laptop screen.width = 1440px, and pixel ratio is 2, which gives 2880px in width, but in system information it's said my resolution is still 2560 x 1600.

So how do I calculate screen's resolution in this case?

screen.width

real resolution

PS: my second laptop is 13" macbook pro 2020

PPS: well, I realised it depends on my settings, and is there a way to know the device's resolution as my settings can vary?


Solution

  • well, after some research I realised, that there's no way to get physical characteristics of displays, and device pixel ratio won't show the real css-to-physical pixels ratio