Venelin
Venelin

Reputation: 3308

How to reload the page when asked for Geolocation

I have a HTML5 asking for geolocation.

Here is how it looks like:

enter image description here

My question is: How can i reload the page when the user accepts to Allow sharing his location? Is there any javascript which can do that ?

Thanks in advance!

Upvotes: 0

Views: 2576

Answers (2)

Sami Triki
Sami Triki

Reputation: 408

https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation

navigator.geolocation.getCurrentPosition(function() {
    window.location.reload();
});

You have access to a callback function when asking for the location, just reload the page inside the callback

Upvotes: -1

asdf_enel_hak
asdf_enel_hak

Reputation: 7640

Just reload page when location got, to prevent infinite reload, check with cookie

window.onload = function() {      
  var geoSuccess = function(position) {           
     $.cookie("position_latitude", position.coords.latitude);
     $.cookie("position_longitude", position.coords.longitude);
     document.location.reload(true);
  };
  if ($.cookie("position_longitude", undefined))
      navigator.geolocation.getCurrentPosition(geoSuccess);
};

Upvotes: 2

Related Questions