Posted By

rportela on 10/09/09


Tagged

javascript CALCULATION PPI


Versions (?)

Get PPI of the current device displaying your page


 / Published in: JavaScript
 

Outputs the number of Pixels Per Inch in the current Device

  1. getPPI : function(){
  2. var DOM_body = document.getElementsByTagName('body')[0];
  3. var DOM_div = document.createElement('div');
  4. DOM_div.style = 'width: 1in; visibility:hidden;';
  5. DOM_body.appendChild(DOM_div);
  6. var w = document.defaultView.getComputedStyle(DOM_div, null).getPropertyValue('width');
  7. DOM_body.removeChild(DOM_div);
  8. return parseInt(w);
  9. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: snh72 on November 9, 2010

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.

You need to login to post a comment.