Skip to content

Instantly share code, notes, and snippets.

@tmcw
Last active December 12, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/4734909 to your computer and use it in GitHub Desktop.
Save tmcw/4734909 to your computer and use it in GitHub Desktop.
function detect() {
var browser = {};
var ua = navigator.userAgent,
msie = new RegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");
if (msie.exec(ua) !== null) {
var rv = parseFloat(RegExp.$1);
browser.support = !(rv && rv < 9);
} else {
browser.support = true;
}
browser.locale = navigator.language;
if (navigator.userAgent.indexOf('Win')) browser.os = 'win';
else if (navigator.userAgent.indexOf('Mac')) browser.os = 'mac';
else if (navigator.userAgent.indexOf('X11')) browser.os = 'linux';
else if (navigator.userAgent.indexOf('Linux')) browser.os = 'linux';
return browser;
};
detect().os;
detect().locale;
detect().support;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment