Get PPI of the current device displaying your page

/ Published in: JavaScript
Save to your folder(s)

Outputs the number of Pixels Per Inch in the current Device

Copy this code and paste it in your HTML
  1. getPPI : function(){
  2. var DOM_body = document.getElementsByTagName('body')[0];
  3. var DOM_div = document.createElement('div');
  4. = '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


RSS Icon Subscribe to comments

You need to login to post a comment.