Skip to content

Instantly share code, notes, and snippets.

@shortcircuit3
Created November 29, 2012 13:24
Show Gist options
  • Save shortcircuit3/4169039 to your computer and use it in GitHub Desktop.
Save shortcircuit3/4169039 to your computer and use it in GitHub Desktop.
UserAgent detector
var userAgent = navigator.userAgent,
uaCheck = {
ios: userAgent.match(/(iPhone|iPod|iPad)/),
ipad: userAgent.match(/(iPad)/),
iphone: userAgent.match(/(iPhone)/),
blackberry: userAgent.match(/BlackBerry/),
android: userAgent.match(/Android/)
};
// Example
if (uaCheck.ios || uaCheck.blackberry || uaCheck.android) {
console.log('mobile');
} else {
console.log('not mobile');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment