Skip to content Skip to sidebar Skip to footer

Java script detect iPhone, iPad, iPod and Android devices

Reading Time: < 1 minute

How to detect iPhone, iPad, iPod, Blackberry and Android or detect mobile devices using Java script.This is very useful to developing your web sites to view those iPhone, iPad, iPod, Blackberry and Android also mobile phones.Here, examples to detect iPhone, iPad, iPod and Android using Java script.
Another article I was described

Detect iPhone, iPad and iPod

        var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod|ipad|Blackberry)/);
	if (agentID) {
	   // device is  iphone or ipod or ipad or Blackberry
	}

Detect iPhone

If you want to check only iphone do it as follows.

//Initialize our user agent string to lower case.
var deviceAgent = navigator.userAgent.toLowerCase();
// DETECT IPHONE
   if (deviceAgent.search("iphone") > -1) {
	   // detected iphone
   }

Detect iPod

If you want to check only iPod do it as follows.

  //DETECT IPOD
var deviceAgent = navigator.userAgent.toLowerCase();
   if (deviceAgent.search("ipod") > -1) {
	   // detected ipod
   }

Detect iPad

If you want to check only iPad do it as follows.

// DETECT IPAD
   var agentID = deviceAgent.match(/(ipad)/);
   if (agentID) {
        // detected ipad
   }

Detect Blackberry

If you want to check only iPad do it as follows.

// DETECT Blackberry
   var agentID = deviceAgent.match(/(Blackberry)/);
   if (agentID) {
        // detected Blackberry
   }

Detect Android devices

You can detect android devices like this.

var deviceAgent  = navigator.userAgent.toLowerCase();
var isAndroid = deviceAgent.indexOf("android") > -1;
if(isAndroid) {
   // device is  android
}

Detect mobile devices

var deviceAgent = navigator.userAgent.toLowerCase();
var isAndroid =  deviceAgent.indexOf("mobile") > -1;
if(isAndroid) {
   // device is  mobile
}