Created
December 24, 2013 20:38
-
-
Save yurydelendik/8117617 to your computer and use it in GitHub Desktop.
Getting the native DPI
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
| 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