禁用浏览器位置提示

You*_*eat -2 browser html5 geolocation

好吧所以我今晚一直在玩html5 地理位置,我想知道有没有办法禁止浏览器提示用户选择他们可能/或可能不想让我的网站跟踪它们?因为我需要跟踪它们以获得准确的时区,以及类似的东西,但如果用户要拒绝该网站找到它们,我现在会有时区,州,城市,拉链等......我猜我正在寻找更多的黑客!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);  

}  
Run Code Online (Sandbox Code Playgroud)

San*_*Lee 6

你不能.

W3C在文档中写了关于Geolocation API的安全性和隐私注意事项.每个实现Geolocation API的浏览器都必须遵循此规则.这是本机功能,所以没有黑客可以避免它.

  • 更具体地说,如果您找到绕过权限提示的方法,则会发现安全漏洞,供应商将以高优先级对其进行修补. (2认同)