Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Created June 18, 2014 23:21
Show Gist options
  • Save brennanMKE/2eaa6924e3376cd60f96 to your computer and use it in GitHub Desktop.
Save brennanMKE/2eaa6924e3376cd60f96 to your computer and use it in GitHub Desktop.
JavaScript to detect mobile browser and platform.
var isMobile = {
Android: function() {
return /Android/i.test(navigator.userAgent);
},
BlackBerry: function() {
return /BlackBerry/i.test(navigator.userAgent);
},
iOS: function() {
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
},
Windows: function() {
return /IEMobile/i.test(navigator.userAgent);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment