Created
January 29, 2019 16:02
-
-
Save MaxXx1313/a2ae67d2b2294a470c421bb324f28522 to your computer and use it in GitHub Desktop.
Get DPI from javascript (live at: https://jsfiddle.net/bsorrentino/s8c51jvt/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// inspired by https://stackoverflow.com/a/838755/521197 | |
// | |
function getDPI() { | |
var div = document.createElement( "div"); | |
div.style.height = "1in"; | |
div.style.width = "1in"; | |
div.style.top = "-100%"; | |
div.style.left = "-100%"; | |
div.style.position = "absolute"; | |
document.body.appendChild(div); | |
var result = div.offsetHeight; | |
document.body.removeChild( div ); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment