地理位置权限弹出窗口-jquery
要求用户权限访问当前位置要阻止或允许的弹出窗口仅显示2秒钟,甚至在用户选择之前就关闭了。我需要帮助显示至少用户的弹出窗口
var listenType = (navigator.userAgent.toLowerCase().indexOf('edge') == -1) ? 'mouseup' : 'click';
...
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
getZipFromLatLng(position.coords.latitude, position.coords.longitude);
}, (err) => {
if (err.code === err.PERMISSION_DENIED) {
const locationDisabledcontent = `
<div class="text-center zip-alert-heading"><b>Location sharing is disabled on your
browser.</b></div>
<p class="text-center zip-alert-subheading">Please enable location sharing in your browser settings. <br /> or
type in a zip code
to continue.</p>`;
if ($('.custom-alert')) {
$('.custom-alert .modal-body').empty();
$('.custom-alert .modal-body').html(locationDisabledcontent);
$('.custom-alert').addClass('show');
}
$('.custom-alert-close').on('click', function () {
$('.custom-alert').removeClass('show');
})
}
}, {timeout:5000});
}
}
...
$('.zipEntry-text').on(listenType, function (e) {
console.log('in zipentrytext, get current location');
e.stopPropagation();
e.preventDefault();
getLocation();
})
$(document).ready(function() {
const zipExists = getCookie('zip');
if (!zipExists) {
getLocation();
const zipExists = getCookie('zip');
if (!zipExists) {
getAddressFromZip(defaultZip);
}
}
})
The popup that asks for user permission to access current location either to block or allow is showing for only 2 seconds it closes even before user could select. I need help in displaying the popup for atleast user to click on it
var listenType = (navigator.userAgent.toLowerCase().indexOf('edge') == -1) ? 'mouseup' : 'click';
...
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
getZipFromLatLng(position.coords.latitude, position.coords.longitude);
}, (err) => {
if (err.code === err.PERMISSION_DENIED) {
const locationDisabledcontent = `
<div class="text-center zip-alert-heading"><b>Location sharing is disabled on your
browser.</b></div>
<p class="text-center zip-alert-subheading">Please enable location sharing in your browser settings. <br /> or
type in a zip code
to continue.</p>`;
if ($('.custom-alert')) {
$('.custom-alert .modal-body').empty();
$('.custom-alert .modal-body').html(locationDisabledcontent);
$('.custom-alert').addClass('show');
}
$('.custom-alert-close').on('click', function () {
$('.custom-alert').removeClass('show');
})
}
}, {timeout:5000});
}
}
...
$('.zipEntry-text').on(listenType, function (e) {
console.log('in zipentrytext, get current location');
e.stopPropagation();
e.preventDefault();
getLocation();
})
$(document).ready(function() {
const zipExists = getCookie('zip');
if (!zipExists) {
getLocation();
const zipExists = getCookie('zip');
if (!zipExists) {
getAddressFromZip(defaultZip);
}
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认值(getAddressfromzip)甚至在getCurrentLocation返回值之前运行
Default(getAddressfromzip) is running even before getcurrentlocation returns a value so I set a delay of 10seconds after getLocation so default could not run