This question already has an answer here:
- How can you detect the version of a browser? 23 answers
How do I determine the exact browser and version using JavaScript?
This question already has an answer here:
How do I determine the exact browser and version using JavaScript?
It is usually best to avoid browser-specific code where possible. The JQuery
$.support
property is available for detection of support for particular features rather than relying on browser name and version.In Opera for example, you can fake an internet explorer or firefox instance.
A detailed description of JQuery.support can be found here: http://api.jquery.com/jQuery.support/
Now deprecated according to jQuery.
When coding websites, I always make sure, that basic functionality like navigation is also accessible to non-js users. This may be object to discussion and can be ignored if the homepage is targeted to a special audience.
I found something interesting and quicker way. IE supports
navigator.systemLanguage
which returns "en-US" where other browsers returnundefined
.I recommend using the tiny javascript library Bowser, yes no r. It is based on the
navigator.userAgent
and quite well tested for all browsers including iphone, android etc.https://github.com/ded/bowser
You can use simply say:
Here is how I do custom CSS for Internet Explorer:
In my JavaScript file:
And then in my CSS file, y define each different style:
Sadly, IE11 no longer has
MSIE
in itsnavigator.userAgent
:As to why you want to know which browser you're using, it's because every browser has its own set of bugs, and you end up implementing browser and version specific workarounds, or tell the user to use a different browser!