Skip to content

Instantly share code, notes, and snippets.

@devbyray
Created January 8, 2015 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devbyray/0e12514b33c92b12af69 to your computer and use it in GitHub Desktop.
Save devbyray/0e12514b33c92b12af69 to your computer and use it in GitHub Desktop.
Function to check if Mobile Device (Android, WebOS, iPhone, iPad, iPod (or iOS), Windows Phone, SymbianOS, RIM)
(function () {
'use strict';
var useragent = navigator.userAgent;
function deviceOS() {
if(useragent.match(/Android/i)) {
return 'android';
} else if(useragent.match(/webOS/i)) {
return 'webos';
} else if(useragent.match(/iPhone/i)) {
return 'iphone';
} else if(useragent.match(/iPod/i)) {
return 'ipod';
} else if(useragent.match(/iPad/i)) {
return 'ipad';
} else if(useragent.match(/Windows Phone/i)) {
return 'windows phone';
} else if(useragent.match(/SymbianOS/i)) {
return 'symbian';
} else if(useragent.match(/RIM/i) || useragent.match(/BB/i)) {
return 'blackberry';
} else {
return 'no-device';
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment