No and in 1997 the comment would have been “Pfft. Browser sniffing, what is this 1897?”. Browser sniffing was definitely looked down on as being extremely poor practice and unnecessary long before 1997. In 1997 the main three browsers to support JavaScript were Netscape 2, Netscape 3, and IE3 and feature sensing was the recommended way of determining whether the new JavaScript commands introduced in Netscape 3 would work or not.
Microsoft did that deliberately as many web pages that actually did such tests were checking if the browser was Netscape 3 and so in order to fool the code into accepting IE3 as well they set the useragent to the same value as Netscape. It is because people used those fields to identify certain browsers and reject others that all browsers used the same values for the field as other browsers that were accepted. That’s why all browsers have the abiliity to fill that field with the same value as recent versions of IE and Netscape use.
Opera can change the field values automatically depending on exactly what web page is being visited and so tell pages that only work on IE that it is IE and pages that only work on Firefox that it is Firefox.
In the case of Internet Explorer, Firefox, and Safari you can set the useragent to anything you like and so when the useragent says “Eat At Joe’s” it is most likely one of those three browsers.
Are you sure you’re not mixing appName and appCodeName up?
navigator.appName should give the name of the browser, while navigator.appCodeName should give what it thinks it is (for some strange reason IE thinks it’s Mozilla-compatible, hah!)
Here’s more info (found on Google by typing ‘javascript navigator’ )
Edit>>
OK, I just found the page where you probably got that script from and apparently my Firefox 3.6.10 browser thinks it’s Netscape 5.
Being fair though, the JScript versions do have some synthesis with their version of the browser. JScript 9 = IE9, 5.8 = IE8, 5.7 = IE7, 5.6 = IE6, 5.5 = IE5.5.
Try running it in different browsers to see the result.
Opera allows you to set the user agent to Opera, Firefox or IE.
Safari does the same, plus Safari
There’s an even more certain way to detect IE and that is using JScript conditional comments.
/*@cc_on
@if (@_jscript)
alert('This browser is running JScript and is therefore Internet Explorer');
@else */
alert('This browser is running JavaScript and is therefore NOT Internet Explorer'); /*
@end
@*/
It would still be more efficient to wrap the code that tests for what version of IE that it is inside the jscript conditional comment so that it doesn’t even try to run for other browsers which don’t have an IE version number.