【发布时间】: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