Skip to content

Instantly share code, notes, and snippets.

@Couto
Created February 11, 2014 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Couto/8936497 to your computer and use it in GitHub Desktop.
Save Couto/8936497 to your computer and use it in GitHub Desktop.
Mootools' browser detection
var browser = (function () {
var ua = navigator.userAgent.toLowerCase(),
platform = navigator.platform.toLowerCase(),
UA = ua.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/) || [null, 'unknown', 0],
mode = UA[1] === 'ie' && document.documentMode,
name = (UA[1] === 'version') ? UA[3] : UA[1],
version = mode || parseFloat((UA[1] === 'opera' && UA[4]) ? UA[4] : UA[2]),
browser;
return {
browserName : (name === 'ie') ? 'Microsoft Internet Explorer' : name.charAt(0).toUpperCase() + name.slice(1),
majorVersion: parseInt(version, 10),
platform: ua.match(/ip(?:ad|od|hone)/) ? 'ios' : (ua.match(/(?:webos|android)/) || platform.match(/mac|win|linux/) || ['other'])[0]
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment