Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google chrome中的地理位置错误回调_Javascript_Google Chrome_Geolocation - Fatal编程技术网

Javascript Google chrome中的地理位置错误回调

Javascript Google chrome中的地理位置错误回调,javascript,google-chrome,geolocation,Javascript,Google Chrome,Geolocation,Google chrome浏览器(19.0.1084.56 m)中有一个奇怪的bug(或功能?)。 我正在尝试运行页面上的下一个JavaScript代码: //... function successCallback(position) { console.log('success'); } function errorCallback(error) { console.log('error'); } navigator.geolocation.getCurrentPosit

Google chrome浏览器(19.0.1084.56 m)中有一个奇怪的bug(或功能?)。 我正在尝试运行页面上的下一个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也有同样的功能

我相信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});