Reputation: 3308
I have a HTML5 asking for geolocation.
Here is how it looks like:
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
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
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