How to detect a mobile device with JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

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());
   }
};
raja
Published on 27-Feb-2018 16:02:28
Advertisements