-
-
Save DavidovichVA/6248085 to your computer and use it in GitHub Desktop.
Added support for Opera 15+.
Added support for Konqueror.
Fixed browser version detection.
Fixed webkit detection. browser.webkit now returns webkit version.
(!) Firefox is now detected as "firefox", not "mozilla" (uncomment 31th line, if you want "mozilla" back).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function (jQuery, window, undefined) { | |
| var matched, browser; | |
| jQuery.uaMatch = function (ua) { | |
| ua = ua.toLowerCase(); | |
| //detect browser and, if possible, browser version | |
| var match = | |
| /(opera)/.exec(ua) || | |
| /(opr)[ \/]([\w.-]+)/.exec(ua) || //opera 15+ | |
| /(chrome)[ \/]([\w.-]+)/.exec(ua) || | |
| /(msie) ([\w.-]+)/.exec(ua) || | |
| /(firefox)[ \/]([\w.-]+)/.exec(ua) || | |
| /(safari)/.exec(ua) || | |
| /(konqueror)[ \/]([\w.-]+)/.exec(ua) || | |
| []; | |
| //detect browser version | |
| var matchversion = | |
| /version[ \/]([\w.-]+)/.exec(ua) || | |
| []; | |
| //detect webkit and it's version | |
| var matchwebkit = | |
| /webkit[ \/]([\w.-]+)/.exec(ua) || | |
| []; | |
| return { | |
| //in case you want to identify firefox as mozilla | |
| //browser: (match[1] == "opr" ? "opera" : match[1] == "firefox" ? "mozilla" : match[1]) || "", | |
| browser: (match[1] == "opr" ? "opera" : match[1]) || "", | |
| version: match[2] || matchversion[1] || "0", | |
| webkit : matchwebkit[1] || "" | |
| }; | |
| }; | |
| // Don't clobber any existing jQuery.browser in case it's different | |
| if (!jQuery.browser) { | |
| matched = jQuery.uaMatch(window.navigator.userAgent); | |
| browser = {}; | |
| if (matched.browser) { | |
| browser[matched.browser] = true; | |
| browser.version = matched.version; | |
| if (matched.webkit) browser.webkit = matched.webkit; | |
| } | |
| jQuery.browser = browser; | |
| } | |
| })(jQuery, window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment