每次用户重新加载页面时,让 html5 地理定位请求权限

Make html5 geolocation ask permission every time user reloads the page(每次用户重新加载页面时,让 html5 地理定位请求权限)
本文介绍了每次用户重新加载页面时,让 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 地理定位请求权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)