Browser detection and browser detection detection
When poking about some code today I discovered our browser detection javascript. This product is technically officially supported on IE6 and unofficially on IE7 though apparently that will be reversing soon.
Sidetrack – Guess what folks, in these days where browser updates are pushed out from the vendors to the client without intervention (as are both IE and Firefox updates), the current supported version is the one that the user has *at this moment. Dictating versions is a losing battle.*
The detection code would decide whether you were a Netscape 4, Netscape 6 or IE4 browser (this is the default). Not only is this dead code, but it is assigning the browser internally to the app to a version that is no longer supported. To make matters worse, there is conditional formatting based upon this. I’m guessing the javascript implementation has changed a bit since IE4 was released.
In my view, the only time you should be doing browser detection is when you absolutely must and have no alternative but to using something that is not supported between the supported browsers. Not only does having things in ‘if IE do blah, else if FF do blah’ structures increase the complexity of the code but the testing too. If you code to the standards, and I am comfortable with the browser’s adherence to said standard then I will not have to test it as rigorous. You also open up the possibility of having your code work in other browsers as well.
And if you are still trying to enforce specific browser versions, make sure that you have a plan in place to maintain the browser restriction code.
So how do you know if your code is doing this sort of thing? You can search all files that sit on the webserver that can include javascript (so *.html, *.jsp, *.asp, *.aspx, *.js) for strings like userAgent or appName.