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()); } };