checking if browser is FF < 3.6.14
I know that in general, we want to check for the presence of specific properties that a browser will have, rather than digging into the user agent string, bu开发者_运维技巧t I have a special circumstance where I need to do something if the user is running a version of Firefox < 3.6.14.
I'm looking at window.navigator.userAgent, which seems to have everything I need, but any hints or gotchas I might not think of?
Here is a list of Firefox user agent strings. There are some surprises like 3.6.1pre
and Firefox 3.6b5
that you will need to be able to match. Using a library may indeed be the best idea, if the library manages to interpret these numbers correctly.
While you almost never want to parse the userAgent, I'll assume you're operating against one of those rare weird cases where you do. Parsing userAgents is like one big gotcha, so you're probably best off using an existing library.
This code at quirksmode is probably a good starting point: http://www.quirksmode.org/js/detect.html. It should give you the major and minor version (3.6), so you will need to modify it if you need the .14.
You're better off testing the JavaScript functions you want to use rather than the version of the browser. This tells you what you need to know and you don't need to worry what browser or version you have - you know the functions will or won't work.
精彩评论