每次用户重新加载页面时,让 html5 地理定位请求权限 [英] Make html5 geolocation ask permission every time user reloads the page

查看:13
本文介绍了每次用户重新加载页面时,让 html5 地理定位请求权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们为什么需要它:

我们的网站中有一些页面允许用户输入一些数据并搜索他们所在地区的其他客户.当用户打开该页面时,必须显示弹出消息

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想使用您当前的位置.

之后,用户可以放弃它并手动填写位置字段或接受并自动重定向到结果页面.

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

问题:

问题是当用户第一次选择任何提到的选项时,浏览器会记住它并且下次不会再询问它.因此,当用户接受它时,每次他打开搜索页面时,它都会自动将他重定向到结果页面,而无需询问任何内容.

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.

代码:

我们使用的是基本的 html5 地理位置代码

We are using basic html5 geolocation code

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

结论:

我很确定不可能更改浏览器原生的权限.但我希望有人会为这个问题提供很好的解决方案.谢谢.

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.

推荐答案

一旦用户点击拒绝/允许,浏览器就会为网站记住这个决定.

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

避免拒绝的最佳方法是仅在用户单击表示他想使用其位置的内容时调用 getCurrentPosition(...).然后他可能会很乐意分享它:)

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 :)

foursquare 网站就是一个很好的例子.进入后,您可以前往某个城市的地图,并且只有通过单击地图上的使用我的位置"按钮,它才会提示您.

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.

如果您被拒绝该位置,您还可以显示一条信息消息您过去曾拒绝此站点的位置服务,请启用它做 bla bla bla".随便填bla bla bla.

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.

这篇关于每次用户重新加载页面时,让 html5 地理定位请求权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆