How to access screen display’s DPI settings via javascript? [duplicate]

Looks like you can use the ‘screen’ DOM object in IE, its got properties for deviceXDPI, deviceYDPI, logicalXDPI, logicalYDPI.

https://www.w3schools.com/jsref/obj_screen.asp

Here’s a solution from http://www.webdeveloper.com/forum/showthread.php?t=175278
(i havent tried it, seems like a total hack 🙂
Just create something 1 inch wide and measure it in pixels!

console.log(document.getElementById("dpi").offsetHeight);
#dpi {
    height: 1in;
    left: -100%;
    position: absolute;
    top: -100%;
    width: 1in;
}
<div id="dpi"></div>

Leave a Comment