Skip to content

Instantly share code, notes, and snippets.

@yurydelendik
Created December 24, 2013 20:38
Show Gist options
  • Select an option

  • Save yurydelendik/8117617 to your computer and use it in GitHub Desktop.

Select an option

Save yurydelendik/8117617 to your computer and use it in GitHub Desktop.
Getting the native DPI
function getDPI() {
var native = document.createElement('div');
native.setAttribute('style', 'width:0px; width:100mozmm; position: fixed;');
document.body.appendChild(native);
var standard = document.createElement('div');
standard.setAttribute('style', 'width:100mm; position: fixed;');
document.body.appendChild(standard);
var dpi = Math.round(native.offsetWidth / standard.offsetWidth * 96);
native.remove();
standard.remove();
return dpi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment