Google Chrome 浏览器 (19.0.1084.56 m) 中存在一个奇怪的错误(或功能?)。 我正在尝试在我的页面上运行下一个 JavaScript 代码:
//...
function successCallback(position) {
console.log('success');
}
function errorCallback(error) {
console.log('error');
}
navigator.geolocation.getCurrentPosition(
successCallback,
errorCallback,
{timeout: 1000});
//...
浏览器询问我:“sitename 想要跟踪您的物理位置 [允许] [拒绝] ... 了解更多 [X]”。
当我单击“允许/拒绝”按钮时,回调函数可以正常工作。但是当我点击 [X] 按钮时什么也没有发生:( 有什么方法可以检测对 [X] 的点击吗?
PS 看起来 Firefox 也有同样的功能 Firefox 11 and GeoLocation denial callback
最佳答案
我相信 Chrome 没有针对忽略选项的回调。
如果我是你,我会尝试实现超时回调。
示例代码:
_callback = false;
function successCallback(position) {
_callback = true;
console.log('success');
}
function errorCallback(error) {
_callback = true;
console.log('error');
}
setTimeout(function(){if(!_callback)console.log('ignored')}, 10000); //chanche the timeout according your needs
navigator.geolocation.getCurrentPosition(
successCallback,
errorCallback,
{timeout: 1000});
关于javascript - Google Chrome 中的地理位置错误回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11038221/