Permissions

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译!
您也可以阅读此文章的English (US)版。

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The Permissions interface of the Permissions API provides the core Permission API functionality, such as methods for querying and revoking permissions

Methods

Permissions.query()
Returns the user permission status for a given API.
Permissions.request()
Requests permission to use a given API. This is not currently supported in any browser.
Permissions.revoke()
Revokes the permission currently set on a given API.

Example

navigator.permissions.query({name:'geolocation'}).then(function(result) {
  if (result.state == 'granted') {
    showLocalNewsWithGeolocation();
  } else if (result.state == 'prompt') {
    showButtonToEnableLocalNews();
  }
  // Don't do anything if the permission was denied.
});

Specification

Specification Status Comment
Permissions API
The definition of 'Permissions' in that specification.
Editor's Draft Initial definition.

Browser Support

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 43.0 46 (46) ? ? ?
revoke() ? 47 (47)[1] ? ? ?
persistent-storage permission name ? 53 (53) ? ? ?
Feature Android Android Webview Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support No support 43.0 46.0 (46) ? ? ? 43.0
revoke() ? ? ? ? ? ? ?
persistent-storage permission name ? ? 53.0 (53) ? ? ? ?

[1] Starting in Firefox 51, revoke() is only available if the preference dom.permissions.revoke.enable is true. It is false by default. This was done because there are discussions ongoing about the design of this method, and even whether it should exist at all. Because of the sensitive nature of its function, Mozilla decided to disable it by default. See bug 1295877, comment 0 for details.

文档标签和贡献者