Permissions
Permissions API的 Permissions 接口提供核心 PermissionAPI 功能,例如查询和撤消权限的方法。
方法
Permissions.query()(en-US)-
返回给定 API 的用户权限状态。
Permissions.request()-
请求使用给定 API 的权限,目前此功能尚未在任何浏览器中被支持。
Permissions.requestAll()-
请求使用一组给定 API 的权限。目前此功能尚未在任何浏览器中被支持。
Permissions.revoke()(en-US)-
返回撤消当前在给定 API 上设置的权限。
Example
js
navigator.permissions.query({name:'geolocation'}).then(function(result) {
if (result.state === 'granted') {
showLocalNewsWithGeolocation();
} else if (result.state === 'prompt') {
showButtonToEnableLocalNews();
}
// 如果没有此权限则不什么也做
});
Specification
| Specification |
|---|
| Permissions # permissions-interface |
Browser Support
BCD tables only load in the browser