2011-12-26 74 views
-2

好了,所以我一直在玩的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); 

} 

回答

6

你不能。

W3C写了关于document中Geolocation API的安全和隐私考虑事项。每个实现Geolocation API的浏览器都必须遵循此规则。这是本机功能,所以没有任何黑客可以避免它。

+2

更具体地说,如果您找到一种避开权限提示的方法,则会发现安全漏洞,并且供应商将以高优先级对其进行修补。 – 2011-12-26 05:55:37