Created
June 14, 2017 13:54
-
-
Save DKunin/f78a8ca6abab6333a77a8702a4c7fdd7 to your computer and use it in GitHub Desktop.
getPPI
This file contains 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 getPPI(){ | |
// create an empty element | |
var div = document.createElement("div"); | |
// give it an absolute size of one inch | |
div.style.width="1in"; | |
// append it to the body | |
var body = document.getElementsByTagName("body")[0]; | |
body.appendChild(div); | |
// read the computed width | |
var ppi = document.defaultView.getComputedStyle(div, null).getPropertyValue('width'); | |
// remove it again | |
body.removeChild(div); | |
// and return the value | |
return parseFloat(ppi); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment