Tuesday, February 21, 2012

Detect Android Devices/Phone using jQuery

Android and iPhone/iPad development is pretty hot and very much in demand. Below small piece of code will be useful to detect android devices (i.e. Android Phones & Android tablets) using jQuery.

$(document).ready(function(){
  var isAndroid = navigator.userAgent.toLowerCase().indexOf("android");
  if(isAndroid > -1)
  {
      //It is an Android device. Redirect to Android Version.
  }      
});​
You can test this code by changing the user agent in your browser and set it to Android. There are many plugins/ extension available that allows to change User agent. Below is the link for various user agent switchers available with chrome and firefox.


Also read:
Feel free to contact me for any help related to jQuery, I will gladly help you.
blog comments powered by Disqus