Skip to content

Instantly share code, notes, and snippets.

@gabeidx
Last active December 19, 2015 11:59
Show Gist options
  • Save gabeidx/5951233 to your computer and use it in GitHub Desktop.
Save gabeidx/5951233 to your computer and use it in GitHub Desktop.
Browser detection
/* Browser 1.2.0 | @gabrielizaias | MIT/GPL2 Licensed */
(function () {
'use strict';
var b = navigator.userAgent.toLowerCase(),
e = document.getElementsByTagName('html')[0],
c = b.indexOf('macintosh') !== -1 ? 'macintosh' : b.indexOf('windows') !== -1 ? 'windows' : b.indexOf('linux') !== -1 ? 'linux' : undefined,
a = /(chrome)(?:.*chrome)?[ \/]([\w.]+)/.exec(b) || /(safari)(?:.*version)?[ \/]([\w.]+)/.exec(b) || /(opera)(?:.*version)?[ \/]([\w.]+)/.exec(b) || /(ie) ([\w.]+)/.exec(b) || !/compatible/.test(b) && /(firefox)(?:.*firefox)?[ \/]([\w.]+)/.exec(b) || [],
f = e.className.split(' ');
f.push(a[1], a[1]+parseInt(a[2], 10), c, navigator.platform)
e.className = f.join(' ').replace(/^[\s\xA0]+|[\s\xA0]+$/g, '');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment