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 09ef5b7
Showing 1 changed file with 6 additions and 17 deletions.
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jeresig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

@cowboy cowboy commented on 09ef5b7 Jan 24, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@DBJDBJ
Copy link

@DBJDBJ DBJDBJ commented on 09ef5b7 Jan 25, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@paulirish
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

@DBJDBJ DBJDBJ commented on 09ef5b7 Jan 25, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link

@mlasky mlasky commented on 09ef5b7 Jan 25, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.