Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
Switch language depends on user's browser or OS system language

So, I have two webpages, html and html_en.
Is it possible to detect with JS system or browser language, and, if it's not italian, switch it automatically to english version?
I know there is a navigator.language(s) to help me with, but I dunno how to realise it together, in order to switch htmls if language is not it.
Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Ok, I found an answer.
Simple JS to it.

let language = window.navigator.language;
let languageFistTwo = language.substr(0, 2); // To only keep the first 2 characters.
let currentLocation = document
  .getElementsByTagName("html")[0]
  .getAttribute("lang-js");

switch (languageFistTwo) {
  case "it":
    if (currentLocation == "it") window.location.href = "../../index-test.html";
    break;

  default:
    if (currentLocation != "en") {
      window.location.href = "../../index.html";
    }
}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda