Thursday, July 03, 2008

An overview of jQuery.browser

Update: jQuery.version should have been jQuery.browser.version. Added Firefox 3.0.1

If you are a user of jQuery, you may be aware of the basic browser sniffer that comes with it. However, it may seem to return the wrong version number for certain browsers (Firefox and Safari in particular). This is because it returns the version number of the rendering engine (i.e. the part of the web browser that determines how a page should look and function). To help simplify things, I have created a table of common user agents and what jQuery returns:

BrowserjQuery.browserjQuery.browser.version
Internet Explorer 6jQuery.browser.msie = true6.0
Internet Explorer 7jQuery.browser.msie = true7.0
Firefox 1.5 (first release)jQuery.browser.mozilla = true1.8 or 1.8.0
Firefox 1.5.0.9jQuery.browser.mozilla = true1.8.0.9
Firefox 2.0 (first release)jQuery.browser.mozilla = true1.8.1
Firefox 2.0.0.9jQuery.browser.mozilla = true1.8.1.9
Firefox 3.0jQuery.browser.mozilla = true1.9
Firefox 3.0.1jQuery.browser.mozilla = true1.9.0.1
Safari 2.0.2jQuery.browser.safari = true416.11 / 416.12
Safari 2.0.4jQuery.browser.safari = true418.x - 419
Safari 3.0.xjQuery.browser.safari = true522+, 522.x, 523.x
Safari 3.1.xjQuery.browser.safari = true525.x, 526+
Opera xjQuery.browser.opera = truex

I have listed Opera as 'Opera x' as the version number 'x' is always returned by jQuery.browser.version (so no extra work is required, unlike Firefox and Safari).

This table is based on information from UserAgentString.com. There is a Firefox 1.5.0.12, but I am unsure of the version number, plus there are Safari versions with a slightly different rendering engine version number (i.e. 2.0.2 is not always 416.11). Basically, with Safari, if the version number returned is less than 418, it is Safari 2 or lower and if it is around 525/526 it is Safari 3.1.

1 comment:

Steven said...

This actually kind of makes since, as the rendering engine is the important part, not the actual browser version. I know Netscape would provide new versions with only GUI changes but the same rendering engine.

Thanks for posting this, its a good reference!