beta
Hello developer. Login with your existing account. New to Vodafone Developer? Register your account.

+ Login or create an account

Blog - Tag: device-PPI

How to Calculate the Device PPI

In the mobile phones context, PPI (pixels per inch) is a measurement of the resolution of devices screens. A higher PPI means better/clearer images. PPI can also be used to identify devices.

The following Javascript code presents a method to calculate the PPI and to identify the device:


function getPPI(){
  var DOM_body = document.getElementsByTagName('body')[0];
  var DOM_div = document.createElement('div');
  DOM_div.style.width = "1in";
  DOM_div.style.visibility = "hidden";
  DOM_body.appendChild(DOM_div);
  var ppi = document.defaultView.getComputedStyle(DOM_div, null).getPropertyValue('width');
  DOM_body.removeChild(DOM_div);
  return parseInt(ppi, 10);
}

var ppi = getPPI();
var device = '';
switch(ppi) {
  case 265: device = 'Samsung ...

Categories