We help IT Professionals succeed at work.

check if browser is on mobile device using javascript

i have to write a javascript/html5 website. I have to check if the client browser is opened on a mobile device (like ipad , iphone, android etc)
how can i do that using javascript? pl guide...
thanks a lot
Watch Question

Freelance IT Consultant
If you only need to detect if client browser is mobile device, try this script:
function isMobileDevice() { 
   if ( navigator.userAgent.match(/Android/i) ||
        navigator.userAgent.match(/webOS/i) ||
        navigator.userAgent.match(/iPhone/i) ||
        navigator.userAgent.match(/iPad/i) ||
        navigator.userAgent.match(/iPod/i) ||
        navigator.userAgent.match(/BlackBerry/i) ||
        navigator.userAgent.match(/Windows Phone/i) ||
        navigator.userAgent.match(/IEMobile/i) ||
        navigator.userAgent.match(/Opera Mini/i)
       return true;
 else {
       return false;

Open in new window


OK thanks a lot....

That javascript code works for all the browsers?
Duy PhamFreelance IT Consultant

Yes, I believe it should work for most common mobile browsers. There might be some small mobile manufacturers making their own mobile browsers, but we don't really need to care about those until their devices have bigger market shares.


thanks a lot