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

2023-04-20前端开发问题
3

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

The End

相关推荐

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui要如何改变时间日历布局大小?
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24 前端开发问题
271

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125

JavaScript(js)文件字符串中丢失"\"斜线的解决方法
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转...
2024-10-17 前端开发问题
437