Skip to content
Permalink
Browse files

browser version detection revised for opera >= 10, which was reportin…

…g itself as 9.8 due to their new policy
  • Loading branch information
paulirish authored and jeresig committed Jan 12, 2010
1 parent f14fade commit 7be5ec1248c749ece648c8d80a71b45320556381
Showing with 2 additions and 2 deletions.
  1. +2 −2 src/core.js
@@ -661,8 +661,8 @@ jQuery.extend({
ret = { browser: "webkit", version: /webkit[\/ ]([\w.]+)/ };

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

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

3 comments on commit 7be5ec1

@paulirish

This comment has been minimized.

Copy link
Member Author

paulirish replied Jan 12, 2010

details on this 9.80 thing: http://dev.opera.com/articles/view/opera-ua-string-changes/

i went with this regex approach mostly for consistency..

the alternative is using window.opera.version(), which is supported in opera 7.6+, though we wouldnt have the useragent unit tests against it, obviously.

} else if (/Opera/.test({}.toString.call(window.opera)))
  ret = { browser: "opera", version: opera.version() };
@jdalton

This comment has been minimized.

Copy link
Member

jdalton replied Jan 12, 2010

So you went with the more brittle solution ?
Opera has proven that it doesn't mind changing the UA string so why rely on it when the alternative smaller/more reliable solution exists ?
Consistency can take a back seat here. A toString variable already exists in your primary closure so no need to use {}.

@cowboy

This comment has been minimized.

Copy link
Member

cowboy replied Jan 12, 2010

If I were using a RegExp, I'd do something more like..

} else if ( matches = /^(opera).*(?:version)?/(\d+.\d+)/.exec( ua ) ) {
ret = { browser: matches[1], version: matches[2] }
}

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