/ Published in: JavaScript
Outputs the number of Pixels Per Inch in the current Device
Expand |
Embed | Plain Text
getPPI : function(){ var DOM_body = document.getElementsByTagName('body')[0]; var DOM_div = document.createElement('div'); DOM_div.style = 'width: 1in; visibility:hidden;'; DOM_body.appendChild(DOM_div); var w = document.defaultView.getComputedStyle(DOM_div, null).getPropertyValue('width'); DOM_body.removeChild(DOM_div); return parseInt(w); }
Comments
Subscribe to comments
You need to login to post a comment.

My version of firefox (3.0.19) did not execute this code successfully. The only change I had to make was that I had to change line 4 to the following: DOM_div.style.width = "1in"; You can also make the element invisible the same way, but it is going to be removed anyway.