I have 5 addons/extensions for Firefox, Chrome, Internet Explorer(IE), Opera, and Safari.
How can I correctly recognize the user browser and redirect (once an install button has been clicked) to download the corresponding addon?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Googling for browser reliable detection often results in checking the User agent string. This method is not reliable, because it’s trivial to spoof this value.
I’ve written a method to detect browsers by duck-typing.
Only use the browser detection method if it’s truly necessary, such as showing browser-specific instructions to install an extension. Use feature detection when possible.
Demo: https://jsfiddle.net/6spj1059/
Analysis of reliability
The previous method depended on properties of the rendering engine (
-moz-box-sizingand-webkit-transform) to detect the browser. These prefixes will eventually be dropped, so to make detection even more robust, I switched to browser-specific characteristics:document.documentMode.StyleMediaconstructor. Excluding Trident leaves us with Edge.InstallTriggerchromeobject, containing several properties including a documentedchrome.webstoreobject.chrome.webstoreis deprecated and undefined in recent versionsSafariRemoteNotification, which was introduced after version 7.1, to cover all Safaris from 3.0 and upwards.window.operahas existed for years, but will be dropped when Opera replaces its engine with Blink + V8 (used by Chromium).chromeobject is defined (butchrome.webstoreisn’t). Since Opera tries hard to clone Chrome, I use user agent sniffing for this purpose.!!window.opr && opr.addonscan be used to detect Opera 20+ (evergreen).CSS.supports()was introduced in Blink once Google switched on Chrome 28. It’s of course, the same Blink used in Opera.Successfully tested in: