Skip to content

Instantly share code, notes, and snippets.

@snadrus
Last active August 29, 2015 14:28
Show Gist options
  • Save snadrus/726c4773a32ffaed4447 to your computer and use it in GitHub Desktop.
Save snadrus/726c4773a32ffaed4447 to your computer and use it in GitHub Desktop.
Use detect.js? It's a bit big for just trying to figure out what family your browser is. There's only 4 out there (2 variations of each) and they all have custom prefixed navigator objects. Lets just look for those! Detect.js-like output in 373chars (minified).
window.detect={
parse: function() {
var o = 'orientation' in window, prop, br, pre=['ms', 'moz','webkit'];
return {
isMobile: o,
browser: {
family: (o? "Mobile ":"Desktop ") + (function() {
for (prop in navigator) {
for (br in pre) {
if (!prop.indexOf(br)) { // IE 9 - Edge has "ms", else moz or webkit
return br==='webkit'?(
~navigator.vendor.indexOf("Google")?"Chrome":
~navigator.vendor.indexOf("Apple")?"Safari":
"Webkit") :
br=="ms" ? "Internet Explorer" : "Firefox";
}
}
}
return "Unknown"
})()
}
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment