lundi 1 juillet 2019

How to break if/else statement in JavaScript once a condition is true

So I have this basic JavaScript code to detect a user language and redirect to the proper page based on the browser language, the issue I am facing is that the if/else statement keeps going as an infinite loop and the browser keeps refreshing.

if(userLang == "en-US"){
  window.location.href = "domainame.com/faq.html";
}
else if(userLang == "nl"){
  window.location.href = "domainame.com/faq-de.html";
}
else if(userLang == "fr"){
  window.location.href = "domainame.com/faq-fr.html";
}
else if(userLang == "es-ES"){
  window.location.href = "domainame.com/faq-es.html";
}
else if(userLang == "ja"){
  window.location.href = "domainame/faq-ja.html";
}

I expect the browser to check for the user language and redirect to the proper page, instead, the browser keeps refreshing.

Aucun commentaire:

Enregistrer un commentaire