Skip to content
Permalink
Browse files

Simplification of uaMatch, based upon the patch by Ben Alman.

  • Loading branch information
cowboy authored and jeresig committed Jan 23, 2010
1 parent 01f7202 commit 09ef5b7598bcdd9e6c254b24b55a54e6bfb2b4ca
Showing with 6 additions and 17 deletions.
  1. +6 −17 src/core.js
@@ -653,26 +653,15 @@ jQuery.extend({
// Use of jQuery.browser is frowned upon.
// More details: http://docs.jquery.com/Utilities/jQuery.browser
uaMatch: function( ua ) {
var ret = { browser: "" };

ua = ua.toLowerCase();

if ( /webkit/.test( ua ) ) {
ret = { browser: "webkit", version: /webkit[\/ ]([\w.]+)/ };

} else if ( /opera/.test( ua ) ) {
ret = { browser: "opera", version: /version/.test( ua ) ? /version[\/ ]([\w.]+)/ : /opera[\/ ]([\w.]+)/ };

} else if ( /msie/.test( ua ) ) {
ret = { browser: "msie", version: /msie ([\w.]+)/ };
var match = /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
!/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) ||
[];

} else if ( /mozilla/.test( ua ) && !/compatible/.test( ua ) ) {
ret = { browser: "mozilla", version: /rv:([\w.]+)/ };
}

ret.version = (ret.version && ret.version.exec( ua ) || [0, "0"])[1];

return ret;
return { browser: match[1] || "", version: match[2] || "0" };
},

browser: {}

9 comments on commit 09ef5b7

@jdalton

This comment has been minimized.

Copy link
Member

jdalton replied Jan 23, 2010

would this be a good time to use window.opera.version() instead of the regexp ?

@jeresig

This comment has been minimized.

Copy link
Member

jeresig replied Jan 24, 2010

Don't see a particularly huge reason either way - the regexp works and only has to be run once (and it would certainly make the resulting logic a bit more complicated, since everything else would be using a regexp).

@jdalton

This comment has been minimized.

Copy link
Member

jdalton replied Jan 24, 2010

It's a more stable solution, as Opera has changed their UA string once already, nothing is stopping them from changing it in the future. Using the API the browser provides will ensure it will work in the future.

@cowboy

This comment has been minimized.

Copy link
Member Author

cowboy replied Jan 24, 2010

Well, to that end, we could use document.documentMode to actually test whether IE8 is operating in IE7 mode or not :)

@DBJDBJ

This comment has been minimized.

Copy link

DBJDBJ replied Jan 25, 2010

@cowboy: oops, why I have not thought of this before ?! Very simple and effective.

@paulirish

This comment has been minimized.

Copy link
Member

paulirish replied Jan 25, 2010

opera.version() is the only vendor-provided method for testing browser version that's been in a shipping product for >3 releases. So I wouldn't say this is a good time to move to feature inference via documentMode.

For me, I think testing against opera.version would be sensible. While there is no rush, I think the largest reason to do it is because others take inspiration from jQuery's broweser detection. And as opera has provided this functionality specifically for this reason (and people who used it didnt face a problem during the opera 10 as 9.8 snafu.....) I think it's wise.

@DBJDBJ

This comment has been minimized.

Copy link

DBJDBJ replied Jan 25, 2010

@paul: I do not understand ? Are you saying that document.documentMode can be removed from IE9? Are you (also) saying that this has something to do with (not)using window.opera.version() ? Also: what is "snafu" ?

@mlasky

This comment has been minimized.

Copy link

mlasky replied Jan 25, 2010

@DBJDBJ: http://github.com/jquery/jquery/commit/7be5ec1248c749ece648c8d80a71b45320556381 <-- I think this is what paul is referring to when he mentions the Opera 9.8 "snafu".

@paulirish

This comment has been minimized.

Copy link
Member

paulirish replied Jan 25, 2010

This is the snafu I was referring to: http://dev.opera.com/articles/view/opera-ua-string-changes/

documentMode did not exist in IE6 and if IE decides to not introduces a triple rendering engine browser with IE9 (please God, no), then it might not be there. It's not a reliable property to base a version inference off of.

Please sign in to comment.
You can’t perform that action at this time.