如何检测js中元素导航的状态
How to detect the status of the element navigation in js?
我需要从浏览器中获取用户的纬度和经度,但在大多数浏览器上都有一些限制。如何告诉用户他的地理位置已关闭或根本不支持?
我试过这样的东西,但无论是ipad还是mac上的safari都没有提示任何东西。
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(success);
else
alert('not supported');
演示:http://jsfiddle.net/7sRdS/
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.");
}
看看modernizr,它提供了多个特征检测测试。
相关文章:
- 更改css子元素导航树
- 导航到页面上的某个滑块元素
- 将持久活动类附加到导航栏范围中的导航元素(AngularJS)
- 在元素之间导航的Javascript
- 获取文档的所有元素,id为'主导航'
- 更改<导航>当向下滚动到具有特定id的元素时
- jQuery导航菜单没有't更新第一个元素
- 我的导航选项卡正在删除元素
- 如何防止导航栏中的元素在重新调整大小时被切断
- 滚动到某个元素后,相同的导航栏变得固定
- jquery切换隐藏/显示导航元素
- 如何使用左右箭头键在元素之间导航
- 粘性导航元素 - 隐藏然后显示
- 修复了标题导航和滚动到()下一个/上一个元素
- CSS:无法将元素正确定位在粘性导航栏下方
- 无法使用
导航到正确的元素,因为页面标题窗格已修复(冻结) - 单页网站粘性导航:更改内容元素的活动状态
- 多个配对导航元素的悬停事件
- CSS 导航链接样式:删除其他元素的样式,并在将鼠标悬停在选定元素上时删除双边框
- 如何检测js中元素导航的状态