IT Certificaions

Google Cloud Platform

Thursday, March 15, 2012

Get device type on accessing your website

Find which device has accessed your website: See the javascript code below


function GetDeviceType(){
           if( navigator.userAgent.match(/Android/i) ||
              navigator.userAgent.match(/webOS/i) ||
              navigator.userAgent.match(/iPhone/i) ||
              navigator.userAgent.match(/iPod/i) ||
              navigator.userAgent.match(/BlackBerry/)
            ){
               alert('Device type is ::'+navigator.userAgent);
            }else if(navigator.userAgent.match(/Windows/)){
   alert(' Device type is :: Windows:::'+navigator.userAgent);
}else if(navigator.userAgent.match(/Linux/)){
   alert(' Device type is : Linux:::'+navigator.userAgent);
}else{
              alert(' Other Device:::'+navigator.userAgent);
}


 }

If somebody knows Jquery code for this, update this post or comment here.