Sometimes, we want to determine if the current browser is Firefox on a computer with JavaScript.
In this article, we’ll look at how to determine if the current browser is Firefox on a computer with JavaScript.
How to determine if the current browser is Firefox on a computer with JavaScript?
To determine if the current browser is Firefox on a computer with JavaScript, we check the user agent string.
For instance, we write
if (navigator.userAgent.indexOf("Firefox") > 0) {
console.log("firefox");
}
to get the user agent string with navigator.userAgent
.
Then we check if 'Firefox'
is in the string with indexOf
.
Conclusion
To determine if the current browser is Firefox on a computer with JavaScript, we check the user agent string.