Javascript 我们可以使用jquery启用浏览器位置吗

Javascript 我们可以使用jquery启用浏览器位置吗,javascript,jquery,browser,fancybox-2,Javascript,Jquery,Browser,Fancybox 2,如何使用jQuery自动启用浏览器位置?目前,我可以从下面编写的代码中检测位置是否启用: setInterval(function () { navigator.geolocation.getCurrentPosition(positionFound, positionNotFound); }, 6000); function positionFound() { return true; } function positionNotFound() { var tem

如何使用jQuery自动启用浏览器位置?目前,我可以从下面编写的代码中检测位置是否启用:

setInterval(function () {
    navigator.geolocation.getCurrentPosition(positionFound, positionNotFound);
}, 6000);

function positionFound() {
    return true;
}

function positionNotFound() {
     var template = site_url + 'front/auth/setLocationFancybox';
    if (!$('.fancybox-overlay').html()) {
        $.fancybox.open({
            padding: 0, 
            href: template, 
            type: 'iframe', 
            'closeBtn': false
        });
    }
}
在fancybox中有两个按钮:

  • 打开位置
    :打开浏览器位置的方式
  • 取消
    :当前父窗口将从fancybox关闭

  • 如何打开浏览器位置以及如何从fancybox关闭父窗口?

    使用JavaScript/jQuery无法打开浏览器位置。用户需要在其首选项中授予权限。您最好的选择是专门要求您的用户启用它

    要从fancybox关闭父窗口,可以使用以下代码行:

    parent.$.fn.fancybox.close();
    

    您无法自动启用它。这取决于用户的偏好,而JS无法控制。你知道,浏览器请求许可是有原因的。谢谢Rory McCrossan&Juhana。但是我们可以从fancybox关闭当前选项卡吗。如果是,如何??我正在使用Php-Codeigniter、jQuery、AngularJS。谢谢Ivan。目前,我可以从以下位置关闭fancybox:parent.$.fn.fancybox.close();。假设在我的当前页面上有一个奇特的框。在fancybox中会有一个取消按钮。现在单击按钮,我想关闭当前选项卡。您只能关闭自己打开的选项卡。您可以尝试:
    window.top.close()。有些事情(干扰用户设置、关闭选项卡)最好留给用户去做。由于明显的原因(例如恶意软件、bug),网页上运行的脚本在“为用户”做事时能力非常有限。