-2

Using some simple JavaScript, I'm getting what seems to be an incorrect value returned for one of my two pieces of similar code. For browserName I am getting Netscape as the value returned regardless of what browser I test the code on. browserVer, however, seems to return the correct value, shown below using Google Chrome.

browserVer results:

5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1

Why is this?

    var browserName = navigator.appName;
    var browserVer = navigator.appVersion;
phamousphil
  • 254
  • 4
  • 15

2 Answers2

3

A quick Google of what navigator.appName actually means returns this MDN page which includes the fact that:

The HTML5 specification also allows any browser to return "Netscape" here, for compatibility reasons.

Instead, you should probably use a browser sniffing library like Modernizr

SomeKittens
  • 38,868
  • 19
  • 114
  • 143
1

A better search revealed the answer (Why does JavaScript navigator.appName return Netscape for Safari, Firefox and Chrome?)

"MDN says: "This was originally part of DOM Level 0, but has been since included in the HTML5 spec." See Mozilla documentation here. BTW; that's why this cannot be used for browser detection (maybe only for IE). Browser detection is a BAD practice and you should always avoid it where possible. Do feature detection instead. But if anybody insists on this; they should use the userAgent property instead."

Community
  • 1
  • 1
phamousphil
  • 254
  • 4
  • 15