TeeOh
TeeOh

Reputation: 117

Javascript Browser Recognition

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?

Upvotes: 1

Views: 620

Answers (3)

Mutation Person
Mutation Person

Reputation: 30498

This trending topic might also be of use:

When IE8 is not IE8 what is $.browser.version?

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

Upvotes: 0

zombat
zombat

Reputation: 94147

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.

Upvotes: 4

DmitryK
DmitryK

Reputation: 5582

Those were the days ;) Old style.

use navigator.userAgent instead

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

Upvotes: 0

Related Questions