Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda