Skip to content

Instantly share code, notes, and snippets.

@MaxXx1313
Created January 29, 2019 16:02
Show Gist options
  • Save MaxXx1313/a2ae67d2b2294a470c421bb324f28522 to your computer and use it in GitHub Desktop.
Save MaxXx1313/a2ae67d2b2294a470c421bb324f28522 to your computer and use it in GitHub Desktop.
Get DPI from javascript (live at: https://jsfiddle.net/bsorrentino/s8c51jvt/)
//
// 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