Permissions

翻译不完整。 请帮助我们翻译这篇文章!

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
PermissionsChrome Full support 43Edge Full support 79Firefox Full support 46IE No support NoOpera Full support YesSafari No support NoWebView Android Full support 43Chrome Android Full support 43Firefox Android Full support 46Opera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support 4.0
accelerometer permissionChrome Full support 62Edge Full support 79Firefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 62Chrome Android Full support 62Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 8.0
accessibility-events permissionChrome Full support 62Edge Full support 79Firefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 62Chrome Android Full support 62Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 8.0
ambient-light-sensor permissionChrome Full support 62Edge Full support 79Firefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 62Chrome Android Full support 62Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 8.0
background-sync permissionChrome Full support 62Edge Full support 79Firefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 62Chrome Android Full support 62Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 8.0
camera permissionChrome Full support 64Edge Full support 79Firefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 64Chrome Android Full support 64Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 9.0
clipboard-read permissionChrome Full support 64Edge Full support 79Firefox No support NoIE No support NoOpera ? Safari No support NoWebView Android Full support 64Chrome Android Full support 64Firefox Android No support NoOpera Android ? Safari iOS No support NoSamsung Internet Android Full support 9.0
clipboard-write permissionChrome Full support 64Edge Full support 79Firefox No support NoIE No support NoOpera ? Safari No support NoWebView Android Full support 64Chrome Android Full support 64Firefox Android No support NoOpera Android ? Safari iOS No support NoSamsung Internet Android Full support 9.0
geolocation permissionChrome Full support 43Edge Full support 79Firefox ? IE No support NoOpera Full support 30Safari No support NoWebView Android No support NoChrome Android Full support 43Firefox Android ? Opera Android Full support 30Safari iOS No support NoSamsung Internet Android Full support 4.0
gyroscope permissionChrome Full support 51Edge Full support 79Firefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 51Chrome Android Full support 51Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 5.0
magnetometer permissionChrome Full support 62Edge Full support 79Firefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 62Chrome Android Full support 62Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 8.0
microphone permissionChrome Full support 64Edge Full support 79Firefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 64Chrome Android Full support 64Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 9.0
midi permissionChrome Full support 43Edge Full support 79Firefox ? IE No support NoOpera Full support 30Safari No support NoWebView Android No support NoChrome Android Full support 43Firefox Android ? Opera Android Full support 30Safari iOS No support NoSamsung Internet Android Full support 4.0
notifications permissionChrome Full support 43Edge Full support 79Firefox ? IE No support NoOpera Full support 30Safari No support NoWebView Android No support NoChrome Android Full support 43Firefox Android ? Opera Android Full support 30Safari iOS No support NoSamsung Internet Android Full support 4.0
payment-handler permissionChrome Full support 66Edge Full support 79Firefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 9.0
persistent-storage permissionChrome Full support 71Edge Full support 79Firefox Full support 53IE No support NoOpera Full support 58Safari No support NoWebView Android Full support 71Chrome Android Full support 71Firefox Android Full support 53Opera Android Full support 50Safari iOS No support NoSamsung Internet Android Full support 10.0
push permissionChrome Full support 43Edge Full support 79Firefox ? IE No support NoOpera Full support 30Safari No support NoWebView Android No support NoChrome Android Full support 43Firefox Android ? Opera Android Full support 30Safari iOS No support NoSamsung Internet Android Full support 4.0
queryChrome Full support 43Edge Full support 79Firefox Full support 46IE No support NoOpera Full support YesSafari No support NoWebView Android Full support 43Chrome Android Full support 43Firefox Android Full support 46Opera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support 4.0
request
ExperimentalNon-standard
Chrome Full support 46Edge Full support 79Firefox No support NoIE No support NoOpera ? Safari No support NoWebView Android Full support 46Chrome Android Full support 46Firefox Android No support NoOpera Android ? Safari iOS No support NoSamsung Internet Android Full support 5.0
requestAll
ExperimentalNon-standard
Chrome Full support 48Edge Full support 79Firefox No support NoIE No support NoOpera ? Safari No support NoWebView Android Full support 48Chrome Android Full support 48Firefox Android No support NoOpera Android ? Safari iOS No support NoSamsung Internet Android Full support 5.0
revoke
ExperimentalNon-standard
Chrome Full support 46Edge Full support 79Firefox Full support 51
Disabled
Full support 51
Disabled
Disabled From version 51: this feature is behind the dom.permissions.revoke.enable preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support 47 — 51
IE No support NoOpera ? Safari No support NoWebView Android Full support 46Chrome Android Full support 46Firefox Android Full support 51
Disabled
Full support 51
Disabled
Disabled From version 51: this feature is behind the dom.permissions.revoke.enable preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support 47 — 51
Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 5.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
User must explicitly enable this feature.
User must explicitly enable this feature.