How to detect Android in JavaScript?

JavaScript: How can we detect browser name and version using JavaScript?

  • Answer:

    As others have noted, you can pretty easily check the navigator object. For mapping user agent strings to explicit browsers, I usually rely on http://www.useragentstring.com and/or the sample user agent strings in my web inspector. Keep in mind that some users (namely on Android) use mobile browsers that provide a false user agent in order to force a page into rendering as a desktop site. That said, I definitely agree with 's answer - oftentimes it's much better to use a tool like http://modernizr.com to detect what features you need. For instance, even if the userAgent string matches a browser you've tested, there's no guarantee that the browser is up-to-date, nor that future versions of the browser still support the feature you're relying on. For further reading, here's one of my favorite articles on the topic of detecting features. http://diveintohtml5.info/detect.html

Ryhan Hassan at Quora Visit the source

Was this solution helpful to you?

Other answers

Browser detecting is a bad practice.  The navigator API is a notably unreliable.  You should be doing feature testing instead.  This way, regardless of what features are supposed to be in the browser you think you're serving, you've delivering a consistent experience based on what a user's browser can do.

Matt Ford

You could parse the navigator.userAgent string to get most of the information you need for a browser and the version. However, you could also use https://github.com/NielsLeenheer/WhichBrowser. This is up-to-date and very reliable.

Prasenjit Sharan

You can do that using the navigator object. The properties you'd be interested in are the appName and userAgent. More about all the properties here - http://www.javascriptkit.com/javatutors/navigator.shtml jquery.browser (http://api.jquery.com/jQuery.browser/) was also a great way to get this info before it was deprecated.

Lata Sadhwani

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.