1

I am trying to get information back on the vistors browser to my website. However the return I get for each parameter is 'undefined'.

The code I am using is below (this is referenced as external JS doc in the HTML head):

function navigator(){
    alert("YOUR COMPUTER INFO SIR: \n\nBrowser Code Name: " + navigator.appCodeName + "\nBrowser Name: " + navigator.appName +  "\nBrowser Version: " + navigator.appVersion +  "\nCookies Enabled: " + navigator.cookieEnabled + "\nPlatform: " + navigator.platform +  "\nUser-agent header: " + navigator.userAgent + "\nUser-agent language: " + navigator.systemLanguage );
}

I am calling the function in the HTML body as:

<input type="button" onclick="navigator()" value="Click Me to get your computer Info!"/>

And the data is returned as:

YOUR COMPUTER INFO SIR: 

Browser Code Name: undefined
Browser Name: undefined
Browser Version: undefined
Cookies Enabled: undefined
Platform: undefined
User-agent header: undefined
User-agent language: undefined

Any ideas?

Update: Thanks, Renamed the function as suggested to navigatorInfo and got data returned as follows:

Browser Code Name: Mozilla Browser Name: Netscape Browser Version: 5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/536.29.13 (KHTML, like Gecko) Version/6.0.4 Safari/536.29.13 Cookies Enabled: true Platform: MacIntel User-agent header: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/536.29.13 (KHTML, like Gecko) Version/6.0.4 Safari/536.29.13 User-agent language: undefined.

However I am using a Safari browser and the Browser returned is Mozilla....

UPDATE: OK, got it, thanks for the help.... http://www.quirksmode.org/js/detect.html

dancingbush
  • 2,131
  • 5
  • 30
  • 66
  • 3
    You've shadowed the global `navigator` object by creating a function with the same name. Pick another name, or use `window.navigator.appName`, etc. – Rob W Apr 28 '13 at 19:16
  • @RobW is correct you are overwriting the namespace of navigator by calling it inside of a function of navigator. – Drew Dahlman Apr 28 '13 at 19:18

2 Answers2

2

navigator is an object that exists in browsers. You must rename your function to something other than navigator like navigatorInfo or something.

PitaJ
  • 12,969
  • 6
  • 36
  • 55
0

OK, got it, thanks for the help.... http://www.quirksmode.org/js/detect.html

dancingbush
  • 2,131
  • 5
  • 30
  • 66