Skip to content

Instantly share code, notes, and snippets.

@skanne
Created March 12, 2014 10:45
Show Gist options
  • Save skanne/9504560 to your computer and use it in GitHub Desktop.
Save skanne/9504560 to your computer and use it in GitHub Desktop.
detect mobile devices
var m = navigator.userAgent.match(/(iPhone|iPad|iPod|Android|Windows Phone|BB10|PlayBook)/)
, device = false
if (m && m.length) {
if (/iPhone|iPad|iPod/.test(m[1])) {
device = 'apple'
} else if (/Android/.test(m[1])) {
device = 'android'
} else if (/Windows Phone/.test(m[1])) {
device = 'windows'
} else if (/BB10|PlayBook/.test(m[1])) {
device = 'blackberry'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment