Make html5 geolocation ask permission every time user reloads the page

久未见 提交于 2019-12-18 11:56:14

问题


Why we need that:

We have some page in our website which allows users to enter some data and search for another customers in their area. When user opened that page the popup message must be shown

http://foo.bar.com would like to use your current location.

After that user can discard that and fill the location fields manually or accept and be automatically redirected to results page.

Problem:

The problem is that when user selects any of the mentioned options at first time, browser remembers it and don't ask it next time. So when user accept it, every time he open the search page it will automatically redirect him to results page withous asking anything.

Code:

We are using basic html5 geolocation code

if (navigator.geolocation) {
   navigator.geolocation.getCurrentPosition(LocationMethod);
} 

Conclusion:

I'm pretty sure that it's impossible to change permission that are browser-native. But I hope that someone will give nice solution for this problem. Thanks.


回答1:


once a user clicks deny/allow the browser remembers this decision for the site.

the best way to avoid a deny is to only call getCurrentPosition(...) when the user clicked something that means he wants to use his location. and then he would probably be glad to share it :)

A good example is on foursquare site. on entering it offers you to go to the map to some city, and only there by clicking the button on the map of "use my location" it prompts for it.

If you are denied the location you could also show an info message with "you have denied location service in the past for this site, do enable it do bla bla bla". and fill in the bla bla bla with whatever.



来源:https://stackoverflow.com/questions/16353909/make-html5-geolocation-ask-permission-every-time-user-reloads-the-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!