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

123
Visualizações
How to render a message in H1 element using geolocation function in javascript

In this code I would like to show a message in the h1 element in case the browser doesn't support geolocation or the user doesn't allow to check its current location. After this part of code it continues, and if geolocation is enabled, I fetch the information and render it.

function getLocation() {
  if (!navigator.geolocation) {
    const errorGettingGeolocation = "Geolocation is not supported by this browser or was not allowed by user.";
    const cityHtml = document.getElementById("cityName");
    cityHtml.innerText = errorGettingGeolocation;
    return;
  } else if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  }
}

How can i render this message and then continue running the code? EDIT: When I console.log inside function getLocation, I get return, but if I console.log inside if (!navigator.geolocation), I don't get any return. It never check this if condition.

about 4 years ago · Juan Pablo Isaza
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