这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。
Permissions API的Permissions接口提供核心PermissionAPI功能,例如查询和撤消权限的方法。
方法
Permissions.query()
- 返回给定API的用户权限状态。
Permissions.request()
-
请求使用给定API的权限,目前此功能尚未在任何浏览器中被支持。
Permissions.requestAll()
- 请求使用一组给定API的权限。目前此功能尚未在任何浏览器中被支持。
Permissions.revoke()
- 返回撤消当前在给定API上设置的权限。
Example
navigator.permissions.query({name:'geolocation'}).then(function(result) {
if (result.state === 'granted') {
showLocalNewsWithGeolocation();
} else if (result.state === 'prompt') {
showButtonToEnableLocalNews();
}
// 如果没有此权限则不什么也做
});
Specification
Specification | Status | Comment |
---|---|---|
Permissions Permissions |
Working Draft | Initial definition. |
Browser Support
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.