I want to make a javascript code that if the user is using a chromium browser triggers an alert telling to change to Firefox/Other browser that are not using chromium derivates.
I tried modifying the folowing code:
let notChrome = !/Chrome/.test(navigator.userAgent)
let alertMessage = "Please use Google Chrome to access this site.\nSome key features do not work in browsers other than Chrome."
if(notChrome) alert(alertMessage)
But I don't know how to modify-it
CodePudding user response:
Based on detect-all-firefox-versions-in-js,below is a reference for you
let notFirefox = !/firefox/.test(navigator.userAgent.toLowerCase())
let alertMessage = "Please use Firefox to access this site.\nSome key features do not work in browsers other than Firefox."
if(notFirefox) alert(alertMessage)
CodePudding user response:
You should check if the browser is firefox then alert what you want
if(navigator.userAgent.toLowerCase().indexOf('firefox') == -1){
alert("Use Firefox");
}