-1

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

  • Have you check this **[detect-all-firefox-versions-in-js](https://stackoverflow.com/questions/7000190/detect-all-firefox-versions-in-js)** – flyingfox Nov 29 '22 at 12:10
  • 2
    If your goal is to make sure the browser supports features your code needs, then you should be doing feature detection not detecting a specific browser – Patrick Evans Nov 29 '22 at 12:16

2 Answers2

0

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)
flyingfox
  • 13,414
  • 3
  • 24
  • 39
  • Why not simply `!navigator.userAgent.toLowerCase().includes("firefox")`? I can’t find this exact regex version in the linked page. See also [`userAgentData`](//developer.mozilla.org/en/docs/Web/API/Navigator/userAgentData) and read the caveats in the [documentation on `userAgent`](//developer.mozilla.org/en/docs/Web/API/Navigator/userAgent). – Sebastian Simon Nov 29 '22 at 12:15
  • @SebastianSimon Hmmm,because OP do it like this,so I just updated his code – flyingfox Nov 29 '22 at 12:18
0

You should check if the browser is firefox then alert what you want

if(navigator.userAgent.toLowerCase().indexOf('firefox') == -1){
   alert("Use Firefox");
}