views:

258

answers:

3

I was doing the browser recognition tutorial on w3schools,and I found that when using firefox and google chrome I received Netscape 5 as my result. I was just curious as to why this is. Anyone care to explain it to me?

A: 

Those were the days ;) Old style.

use navigator.userAgent instead

http://www.javascriptkit.com/javatutors/navigator.shtml

DmitryK
+4  A: 

I think this article about the Browser Object Model essentially answers your question. Basically, the navigator object is useless, and no one bothers to update it. Firefox has its roots in Netscape, and these properties have simply never been updated. (Note: I'd be interested in why they've never been updated, but I haven't found it yet).

That tutorial you're following at w3c is out of date. It's using an extremely old method of browser detection that quite simply doesn't work any more. A better version is here, but even this method isn't recommended any longer. All of these properties can be spoofed, and are quite simply unreliable.

The general method to identifying browsers these days is a technique called object detection, which essentially pokes at your browser's capabilities, and identifies it based on what it can do or what specific objects might exist.

It's of interest to note that modern libraries such as MooTools and JQuery make browser identification very trivial and clean by doing all this object and feature detection for you. MooTools has a Browser object, and JQuery has jQuery.browser, now deprecated in favour of jQuery.support.

zombat
@Zombat: Hey you beat me by few seconds. Even i suggest the version available in quirksmode site. :)
kayteen
@kayteen - hah, yeah I was waiting for somebody to post those, and I got interested in the specific reasons why `navigator` has never been updated, so I just started looking myself and wrote an answer.
zombat
A: 

This trending topic might also be of use:

http://stackoverflow.com/questions/1298713/when-ie8-is-not-ie8-what-is-browser-version/1298738#1298738

To echo some of the other comments. Browser sniffing using the user agent is unreliable. Object detection and feature detection are the way to go

James Wiseman