Skip to content

Instantly share code, notes, and snippets.

@jeffreytgilbert
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreytgilbert/a8cbcee51b517c075b16 to your computer and use it in GitHub Desktop.
Save jeffreytgilbert/a8cbcee51b517c075b16 to your computer and use it in GitHub Desktop.
Sometimes android browsers get iphone envy and try to pretend they're mobile safari... So I broke it down by os by feature detection, because i needed to for this.
// see if this is a mobile browser
var w = window, d = document;
var regex = /mobi|android|webos|blackberry|ipad|ipod|iphone|tablet|phone|kindle/i;
r.mobile = regex.test(ua) || regex.test(w.navigator.platform);
if (r.mobile) {
if (w.chrome || w.performance) { // this is an android device posing as an iPhone
if (w.Worker) { // android 4.4+
} else if (w.Uint32Array) { // android 4.0+
if (w.history.replaceState) { // added at version 2.2-2.3 and then again at 4.2-4.3, but not between those versions
}
} else if (w.FileReader) { // android 3+
} else if (!!d.createElement('audio').canPlayType) { // android 2.3+
} else if (w.webkitMatchesSelector) { // android 2.2+
} else if (w.JSON) { // android 2.1+
} else { // not an android browser
}
} else {
if (w.indexedDB) { // iOS 8
} else if (typeof d.visibilityState !== 'string') { // iOS 7+
} else if (w.FileReader){ // iOS 6+
// Webkit 536.26 Safari 8536.25 - iOS 6
} else if (w.Worker) { // iOS 5+
// Safari 7534.48.3 - iOS 5.0.1
} else if (w.Uint32Array) { // iOS 4.2+
// Safari 6533.18.5 - iOS 4.3.5
} else if (w.JSON) { // iOS 4.0+
// Safari 6531.22.7 - iOS 4.0.2
} else if (w.postMessage) { // iOS 3.2+
// webkit 531.21.10 - iOS 3.2.2
// webkit 528.16 - iOS 3.1.3
} else { // not an iOS browser
// webkit 525.18.1 - iOS 2.2.1
// webkit 525.20 - iOS 2.1.1
// webkit 419.3 - iOS 1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment