-2

I am currently building a website, and I do not have the skills to make the website work on all on all browsers. So I have written a quick bit of JavaScript to detect the browser. I do not know JavaScript very well so the code does not work.

Here is the code


if(userAgent.not(/chrome/i)){
    alert("Warning.\n " +
        "You are not on a recomended browser, \n ciertain features might not work " +
        "try using chrome");
}

can you please just make the warning only appear if you are not using chrome.

thank you very much

hmm-yes
  • 1
  • 1
  • I forgot to add `let userAgent = navigator.userAgent;` before the code but it still does not work – hmm-yes May 25 '22 at 01:59
  • 2
    Does this answer your question? [JavaScript: How to find out if the user browser is Chrome?](https://stackoverflow.com/questions/4565112/javascript-how-to-find-out-if-the-user-browser-is-chrome) – Ricky Mo May 25 '22 at 02:00

1 Answers1

0

let userAgent = navigator.userAgent;
let browserName;

if(userAgent.match(/chrome|chromium|crios/i)){
   browserName = "chrome";
 }else if(userAgent.match(/firefox|fxios/i)){
   browserName = "firefox";
 }  else if(userAgent.match(/safari/i)){
   browserName = "safari";
 }else if(userAgent.match(/opr\//i)){
   browserName = "opera";
 } else if(userAgent.match(/edg/i)){
   browserName = "edge";
 }else{
   browserName="No browser detection";
 }
 
alert(browserName)

your code seems working fine just add the navigator.userAgent

Stacks Queue
  • 848
  • 7
  • 18