Javascript 如何在js中检测元素导航的状态?
我需要从浏览器中获取用户的纬度和经度,但在大多数浏览器上都有一些限制,不允许这样做。如何告诉用户他的地理位置已关闭或根本不支持它 我尝试过类似的东西,但我的mac电脑上的ipad或safari都没有提示任何东西Javascript 如何在js中检测元素导航的状态?,javascript,html,w3c-geolocation,Javascript,Html,W3c Geolocation,我需要从浏览器中获取用户的纬度和经度,但在大多数浏览器上都有一些限制,不允许这样做。如何告诉用户他的地理位置已关闭或根本不支持它 我尝试过类似的东西,但我的mac电脑上的ipad或safari都没有提示任何东西 if (navigator.geolocation) navigator.geolocation.getCurrentPosition(success); else alert('not supported'); 演示: 看看哪个提供了多个特性检测测试 if (navi
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(success);
else
alert('not supported');
演示:
看看哪个提供了多个特性检测测试
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
// ...
}, function(error) {
//error handling
switch(error.code) {
case error.PERMISSION_DENIED:
//User denied the request for Geolocation.
break;
case error.POSITION_UNAVAILABLE:
//Location information is unavailable.
break;
case error.TIMEOUT:
//The request to get user location timed out.
break;
case error.UNKNOWN_ERROR:
//An unknown error occurred.
break;
}
alert("Geolocation error: " + error.code);
},
{
timeout:10000 //10s
});
} else {
alert("Geolocation services are not supported by your browser.");
}