0

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.

ioannis
  • 33
  • 1
  • 9
  • possible duplicate of [best way to detect handheld device in jQuery](http://stackoverflow.com/questions/3514784/best-way-to-detect-handheld-device-in-jquery) – tzot Nov 25 '11 at 21:40
  • Possible duplicate of http://stackoverflow.com/questions/3514784/best-way-to-detect-handheld-device-in-jquery Modernizr is also a good solution for most cases – Daniel Ruf Nov 25 '11 at 13:09

1 Answers1

0

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;
}
Nicola Peluchetti
  • 72,169
  • 29
  • 129
  • 186