I have add-on for Chrome and Firefox, they are same just for different browsers. Is it possible to have one link/button for the add-on, once user clicks it, it will be recognized which browser user is on and opens Chrome vs Firefox add-on. It would be possible to have in html 2 buttons and hide one for each browser, but I would like to have just one button. Thanks!
Asked
Active
Viewed 33 times
0
-
sure it is possible. So detect the browser and show and hide the button. – epascarello Jul 09 '19 at 12:43
-
https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser – epascarello Jul 09 '19 at 12:43
-
Thanks for answer @epascarello, so no other way as just to show/hide buttons for respective browsers? – Eliara Jul 09 '19 at 12:49
1 Answers
0
You can extract browser name from navigator.userAgent then set needed link
<a href="#" id="link">Add-on Link</a>
<script>
var link = document.querySelector("#link");
var userAgent = navigator.userAgent;
if (userAgent.indexOf("Firefox") > 0) {
link.setAttribute("href", "https://www.mozilla.org");
} else if (userAgent.indexOf("Chrome") > 0) {
link.setAttribute("href", "https://google.com");
}
</script>

Vit Stukalov
- 42
- 5