Search code examples
javascriptfirefoxchromium

How to add an alert box if the browser is not firefox


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


Solution

  • 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)