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);
5
  • 1
    Why are you doing this? Unless you're computing statistics this is probably the wrong thing to do. Commented Dec 10, 2012 at 13:37
  • @Sorpigal, It is my requirement Commented Dec 10, 2012 at 13:38
  • 5
    Facts 1) google gives many answers 2) you shouldn't. Commented Dec 10, 2012 at 13:38
  • 2
    This isn't working because Alert is not defined ... use alert instead ... JavaScript is case-sensitive Commented Dec 10, 2012 at 13:38
  • @ManseUK, Exactly you are correct. I tried with small letter. It is working fine. Thanks. Commented Dec 10, 2012 at 13:40

3 Answers 3

5

Use small letter a instead of A in the alert.

var browserType = navigator.appName;
alert('the browser type is: ' + browserType);
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. I found out the solution.
Your code gives the answer as Netscape when I tried in the Chrome.
@user1891768 It returns netscape for most browsers, Google 'window.navigator.appName netscape' - there are better ways to do what you're asking.
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.
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);

1 Comment

see my comment in the question section....i already found out the solution with the help of ManseUK..
0

You can get the name of browser using this code:

window.navigator.appCodeName

1 Comment

Your code gives the answer as Mozilla for all browsers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.