Search This Blog

2017/01/11

Detection: if device is iPad/iPhone or Android or PC

Use navigator to get information of device.

Code:
<script>
var _device = navigator.userAgent;
var isMobile = _device.indexOf("Mobile") > 0;
var isAndroid = _device.indexOf("Android") > 0;
var isPad = _device.indexOf("iPad") > 0;
var isiPhone = _device.indexOf("iPhone") > 0;
if(isMobile && !isPad){
  // device is mobile
  if(isiPhone){
    // device is iPhone
  } else if(isAndroid){
    // device is Android
  }
} else if(isPad){
  // device is iPad
} else {
  // device is PC
}
</script>

No comments :

Post a Comment