客户端检测
Geolocation API
// getCurrentPosition()会以 position 对象为参数调用传入的回调函数
navigator.geolocation.getCurrentPosition((position) => p = position);// 浏览器会弹出确认对话框请用户允许访问Geolocation API // 这个例子显示了用户拒绝之后的结果
navigator.geolocation.getCurrentPosition(
() => { }, (e) => {
console.log(e.code); // 1
console.log(e.message); // User denied Geolocation
}
);
// 这个例子展示了在不安全的上下文中执行代码的结果
navigator.geolocation.getCurrentPosition(
() => { },
(e) => {
console.log(e.code); // 1
console.log(e.message); // Only secure origins are allowed
}
);Connection State 和 NetworkInformation API
Battery Status API
硬件
Last updated