Skip to content

Instantly share code, notes, and snippets.

@richgcook
Created February 20, 2014 00:51
Show Gist options
  • Save richgcook/9104791 to your computer and use it in GitHub Desktop.
Save richgcook/9104791 to your computer and use it in GitHub Desktop.
isMobile JS function
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i) ? true : false;
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i) ? true : false;
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPod/i) ? true : false;
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i) ? true : false;
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
}
};
if ( !isMobile.any() ) { // Not mobile
}
if ( isMobile.any() ) { // Is mobile
}
if ( !isMobile.iOS() ) { // Is iOS
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment