-1

I am creating an application, desktop and tablet are responsive whereas Mobile is adaptive. So I Have to check the condition based on that I have to render the files dynamically.

I found many user agent code, but no luck. I tried in console for iphone and ipad the word "Mobile" is there, my condition is failing.

Current Useragent:

navigator.userAgent.match(/Mobile/i)

Is there any useragent that is specific to mobile only.

  • The reason why they are lengthy is that it's much more complicated then what you've tried... http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery – baao Feb 16 '16 at 16:14

1 Answers1

0

You can check if mobile/tablet/ kindle or not like this:

var UA = navigator.userAgent, isMobile = false;

if (UA.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Nokia|Tizen|Mobile|Opera Mini|KFAPWI/i)) {
  isMobile = true;
}

console.log(isMobile);
   if(isMobile) {
   //your code here
   }

But you can't tell tablet from mobile using the above so you better check the width, also there might be user agent spoofing

Mi-Creativity
  • 9,101
  • 10
  • 33
  • 44