How to know browsing mobile device or identify mobile device using javascript or jquery

 

If you have below question in your mind than this article is very helpful for you.

How to know that web-site open in mobile device or in computer?
Can I run some specific code when its open in mobile device only?
How to know browsing mobile device or identify mobile device using javascript or jquery?

Its long time but I went to Malaysia for my vacation, which is really an awesome country and enjoy lots in Malaysia, having very good experience in Malaysian airline(but thank god that i did not travel in missing Malaysian aircraft MH370) and top tourist places in Malaysia. If you planning to visit Malaysia than definatily visit top 10 tourist places of Malaysia which is Cameron Highlands, Georgetown Inner City, Taman Negara, Pulau Tioman, Mount Kinabalu, Petronas Twin Towers, Langkawi, Perhentian Islands, Sepilok Rehabilition Centre, Mulu Caves and Genting Highland

Now, let’s come to the topic of mobile device and web-site issue, recently I am working on the web-site where we have one page with the apps, this page include description and hyperlink of android apps for android devices, apple apps for iphone and ipads. For navigation on this page there is one nice icon in footer menu of my web-site. This is working fine with the web-site. But my client needs to do something new, so when user click on this link and its android device or ios device than its not open the apps page but bring you directly to the apps store, and user can directly install apps from apps store. To implement this we need to know the user’s device and as per that we need to set the link.

var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
 
if(isMobile.Android())
{
   // Your Code
}
 
if(isMobile. iOS ())
{
   // Your Code
}

Above javascript code is useful to know that user browsing from mobile device or from the computer. its also useful to know that which mobile device is used for browsing the web-site. Please let me know if you have any question regarding the browsing device and compatibility of browsers and all mobile devices.