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

121
Views
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
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!