0

Possible Duplicate:
Using javascript to detect browser type
Detect version of browser

How to detect which type and version of browser does the User is using ?

I tried the following code, but it is not working.

var browserType = navigator.appName;
Alert(browserType);
Community
  • 1
  • 1
Earth
  • 3,477
  • 6
  • 37
  • 78

3 Answers3

5

Use small letter a instead of A in the alert.

var browserType = navigator.appName;
alert('the browser type is: ' + browserType);
Earth
  • 3,477
  • 6
  • 37
  • 78
dsgriffin
  • 66,495
  • 17
  • 137
  • 137
  • Thanks. I found out the solution. – Earth Dec 10 '12 at 13:43
  • Your code gives the answer as `Netscape` when I tried in the `Chrome`. – Earth Dec 10 '12 at 13:54
  • @user1891768 It returns netscape for most browsers, Google 'window.navigator.appName netscape' - there are better ways to do what you're asking. – dsgriffin Dec 10 '12 at 13:57
  • 1
    If I code as `navigator.appName` alone, it works perfectly in all the browser. Also, I edited your answer since the above code is working fine as I checked in all the browsers. – Earth Dec 10 '12 at 14:00
4

Replace

Alert(browserType);

with

alert(browserType);

javascript is case sensitive.

But :

  • it's almost always wrong to try to detect the browser's type. Prefer detection of features
  • when we must, we usually explore (with regexes) navigator.appVersion or navigator.userAgent instead of navigator.appName.

For example :

 var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|Mini/i.test(navigator.userAgent);
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • 1
    see my comment in the question section....i already found out the solution with the help of ManseUK.. – Earth Dec 10 '12 at 13:43
0

You can get the name of browser using this code:

window.navigator.appCodeName
Guerra
  • 2,792
  • 1
  • 22
  • 32