I'm trying to figure out how to get the physical dimensions of a device's screen via Javascript. So far, my conclusion is that it's currently impossible, but I hope someone can prove me wrong :).
So far I have tried to get this information by finding the device's DPI, but it seems there is no way to get the correct value here, as all devices I have tested (some HDPI & XHDPI Android devices, an iPhone4S, an iPad 2 and an iPad 3) report 96DPI.
The first method of obtaining the DPI I tried is one you can find everywhere on the internet: create a div with a CSS width of 1in, get its clientWidth or offsetWidth and there's your DPI. Doesn't work, all devices report 96.
The second method was using the resolution media query, something along the lines of:
for (var i=90; i < 400; i++) {
if (matchMedia('(resolution: ' + i + 'dpi)').matches) {
return i;
}
}
I thought that was a smart solution, but unfortunately that returns 96 as well.
Is there anything left that I can try?