My question is how can i detect in jquery if a client is seeing a website from a mobile devices. This includes any portable device.(phones,i-pads,i-phone,adroid,windows etc.)
thank you for your time.
My question is how can i detect in jquery if a client is seeing a website from a mobile devices. This includes any portable device.(phones,i-pads,i-phone,adroid,windows etc.)
thank you for your time.
Actually you could sniff the user agent in plain javscript, one thing that jQuery advice to do is not check the userAgent but you should check the feature that are supported. For this jquery offers jQuery.support
var deviceIphone = "iphone";
var deviceIpod = "ipod";
//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();
//**************************
// Detects if the current device is an iPhone.
function DetectIphone()
{
if (uagent.search(deviceIphone) > -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is an iPod Touch.
function DetectIpod()
{
if (uagent.search(deviceIpod) > -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is an iPhone or iPod Touch.
function DetectIphoneOrIpod()
{
if (DetectIphone())
return true;
else if (DetectIpod())
return true;
else
return false;
}