Skip to content

Instantly share code, notes, and snippets.

@ericwwsun
Created June 26, 2012 20:45
Show Gist options
  • Save ericwwsun/2998847 to your computer and use it in GitHub Desktop.
Save ericwwsun/2998847 to your computer and use it in GitHub Desktop.
Javascript: if is Mobile detection
isMobile: function() {
// detect user agent
var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
var result = false;
if (mobile) {
result = true;
var userAgent = navigator.userAgent.toLowerCase();
if ((userAgent.search("android") > -1) && (userAgent.search("mobile") > -1))
result = true; // android mobile
else if ((userAgent.search("android") > -1) && !(userAgent.search("mobile") > -1))
result = false; // android tablet
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment