Skip to content

Instantly share code, notes, and snippets.

@diegoug
Created December 17, 2013 16:49
Show Gist options
  • Save diegoug/8008170 to your computer and use it in GitHub Desktop.
Save diegoug/8008170 to your computer and use it in GitHub Desktop.
Function to detect if mobile
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|iPad|iPod/i)? true : false;
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i)? true : false;
},
};
var movile = function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
}
if (movile() == false){
console.log("is not mobile");
} else {
console.log("IS MOBILE");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment