問題描述
我們為什么需要它:
我們的網站中有一些頁面允許用戶輸入一些數據并搜索他們所在地區的其他客戶.當用戶打開該頁面時,必須顯示彈出消息
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 地理定位請求權限的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!