if(firefox and is on a computer){
alert(\'using firefox on a computer\')
}else{
alert(\"using something else!\");
}
How can I do this?
For a quick and dirty solution just do the following, it is cleaner to use includes() when you are searching the 'Firefox' keyword in the NavigatorID.userAgent property than indexOf().
const isFirefoxBrowser = navigator.userAgent.includes('Firefox');
WARNING:
Browser identification based on detecting the user agent string is unreliable and is not recommended, as the user agent string is user configurable.
Read more about userAgent on MDN >>
RECOMMENDED SOLUTION:
Use feature detection instead of browser detection.
Feature detection involves working out whether a browser supports a certain block of code, and running different code dependent on whether it does (or doesn't), so that the browser can always provide a working experience rather crashing/erroring in some browsers.
Read more about implementing feature detection on MDN >>