【问题标题】:disable browser location prompt禁用浏览器位置提示
【发布时间】:2011-12-26 05:23:08
【问题描述】:

好的,所以我今晚一直在玩 html5 geolocation,我想知道有没有办法禁止浏览器提示用户选择他们是否可以/ 或者可能不想让我的网站跟踪它们?因为我需要跟踪他们以到达准确的时区,以及类似的事情,但如果用户拒绝该网站定位他们,我现在会有时区、州、城市、邮政编码等......我猜我在寻找更多的黑客! jQuery代码:

  jQuery("#btnInit").click(initiate_watchlocation);  
  jQuery("#btnStop").click(stop_watchlocation); 

  var watchProcess = null; 

  function handle_errors(error)  
        {  
            switch(error.code)  
            {  
                case error.PERMISSION_DENIED: alert("Yo");  
                break;  

                case error.POSITION_UNAVAILABLE: alert("could not detect current position");  
                break;  

                case error.TIMEOUT: alert("");  
                break;  

                default: alert("unknown error");  
                break;  
            }  
        } 

function initiate_watchlocation() {  
    if (watchProcess == null) {  
        watchProcess = navigator.geolocation.watchPosition(handle_geolocation_query, handle_errors);  
    }  
}  

function stop_watchlocation() {  
    if (watchProcess != null)  
    {  
        navigator.geolocation.clearWatch(watchProcess);  
        watchProcess = null;  
    }  
}

function handle_geolocation_query(position) {  
    var text = "Latitude: "  + position.coords.latitude  + "<br/>" +  
               "Longitude: " + position.coords.longitude + "<br/>" +  
               "Accuracy: "  + position.coords.accuracy  + "m<br/>" +  
               "Time: " + new Date(position.timestamp);  
                jQuery("results").html(text);  

}  

【问题讨论】:

    标签: html geolocation browser


    【解决方案1】:

    你不能。

    W3C 在document 中撰写了有关 Geolocation API 的安全和隐私注意事项的文章。每个实现 Geolocation API 的浏览器都必须遵循这个规则。这是本机功能,因此没有任何技巧可以避免它。

    【讨论】:

    • 更具体地说,如果你找到了绕过权限提示的方法,你就发现了一个安全漏洞,供应商会以高优先级修补它。
    猜你喜欢
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    • 2016-03-16
    • 1970-01-01
    • 1970-01-01
    • 2018-07-31
    • 2023-04-09
    • 2010-11-04
    相关资源
    最近更新 更多