I have 5 addons / extensions for FF, Chrome, IE, Opera and Safari.
I need the code to recognize the user browser and redirect (on click in an install button) to download the corresponding addon.
I have 5 addons / extensions for FF, Chrome, IE, Opera and Safari.
I need the code to recognize the user browser and redirect (on click in an install button) to download the corresponding addon.
I know it may be overkill to use a lib for that, but just to enrich the thread, you could check is.js way of doing this:
UAParser is one of the lightweight JavaScript Library to identify browser, engine, OS, CPU, and device type/model from userAgent string.
There's an CDN available. Here, I have included a example code to detect browser using UAParser.
Now you can use the value of
result.browser
to conditionally program your page.Source Tutorial: How to detect browser, engine, OS, CPU, and device using JavaScript?
In case anyone finds this useful, I've made Rob W's answer into a function that returns the browser string rather than having multiple variables floating about. Since the browser also can't really change without loading all over again, I've made it cache the result to prevent it from needing to work it out the next time the function is called.
Short variant
This combines both Rob's original answer and Pilau's update for 2016
No idea if it is useful to anyone but here is a variant to make TypeScript happy.
}