0

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!

Venelin
  • 2,905
  • 7
  • 53
  • 117

2 Answers2

2

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);
};
asdf_enel_hak
  • 7,474
  • 5
  • 42
  • 84
-1

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

Sami Triki
  • 408
  • 3
  • 7
  • You mean this code will reload the page when i accept to share location with the browser ? – Venelin Mar 28 '16 at 13:21
  • Basically, when you call the function to display this prompt asking the user for it's location. once it's accepted, the function that you pass as a parameter will be called, so you can do anything inside. It will also be called if the user already accepted sharing his location to your website/app – Sami Triki Mar 28 '16 at 13:24