Computer >> Computer tutorials >  >> Programming >> Javascript

How to detect a mobile device with JavaScript?


Use the following code snippet to detect a mobile device −

Example

var device = {
   Android: function() {
      return navigator.userAgent.match(/Android/i);
   },

   iOS: function() {
      return navigator.userAgent.match(/iPhone|iPad/i);
   },

   any: function() {
      return (isMobile.Android() || isMobile.iOS());
   }
};