Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Chrome và callback từ chối HTML5 GeoLocation


Để callback timeout trên Google Chrome, thử mã sau:

_callback = false; function successCallback(position) {    _callback = true;    console.log('success'); } function errorCallback(error) {    _callback = true;    alert('error'); } setTimeout(function(){if(!_callback)console.log('ignored')}, 20000); navigator.geolocation.getCurrentPosition(    successCallback,    errorCallback,    {timeout: 2000} );