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
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
Related Q & A:
- How do I remove a site from IIS7 using JavaScript?Best solution by Server Fault
- How can I detect changes in XML?Best solution by Stack Overflow
- How can I return to the old version of My Yahoo?Best solution by Yahoo! Answers
- How can I sell something on ebay without using a credit card?Best solution by Yahoo! Answers
- How can I remove a picture's watermark using Matlab's image processing toolbox?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.