Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
¿Cómo identificar el navegador y redirigir al usuario si ese no es el navegador correcto?

Tengo un sitio web que hacer para la universidad y el profesor quiere que incluyamos un código que verifique qué navegador está usando el usuario y, si el navegador no es Firefox, debe redirigirse a otro lugar.

Tengo esto hasta ahora:

 function fnBrowserDetect(){ 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"; } document.querySelector("h1").innerText="You are using "+ browserName +" browser"; } function redirect(){ if(browserName != "firefox"){ window.location.replace("www.google.com"); } else { window.location.href = "../index.php"; } }

¿Puede alguien ayudarme y decirme cómo puedo hacer esto correctamente?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Al final de fnBrowserDetect , puede devolver browserName para poder usarlo en su otra función.

También asegúrese de incluir el protocolo ( https:// ) en su URL de redireccionamiento.

 function fnBrowserDetect(){ 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"; } document.querySelector("h1").innerText="You are using "+ browserName +" browser"; return browserName; } function redirect(){ if(fnBrowserDetect() != "firefox"){ window.location.replace("https://www.google.com"); } else { window.location.href = "../index.php"; } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!