过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Permissions.revoke() 方法在 权限 interface reverts a currently set permission back to its default state, which is usually prompt .

句法

This method is called on the global 权限 对象 navigator.permissions .

var revokePromise = navigator.permissions.revoke(descriptor);
					

参数

descriptor
An object based on the PermissionDescriptor dictionary that sets options for the operation consisting of a comma-separated list of name-value pairs. The available options are:
  • 名称 : The name of the API whose permissions you want to query. Valid values are 'geolocation' , 'midi' , 'notifications' ,和 'push' .
  • userVisibleOnly : (Push only, not supported in Firefox — see the 浏览器兼容性 section below) Indicates whether you want to show a notification for every message or be able to send silent push notifications. The default is false .
  • sysex : (MIDI only) Indicates whether you need and/or receive system exclusive messages. The default is false .

注意 : As of Firefox 44, the permissions for Notifications and Push have been merged. If permission is granted (e.g. by the user, in the relevant permissions dialog), navigator.permissions.query() 将返回 true for both notifications and push .

注意 persistent-storage permission allows an origin to use a persistent box (i.e persistent storage ) for its storage, as per the 存储 API .

返回

A Promise that calls its fulfillment handler with a PermissionStatus object indicating the result of the request.

异常

TypeError
Retrieving the PermissionDescriptor information failed in some way, or the permission doesn't exist or is currently unsupported (e.g. midi ,或 push with userVisibleOnly ).

范例

This function can be used by an app to request that its own Geolocation API permission be revoked.

function revokePermission() {
  navigator.permissions.revoke({name:'geolocation'}).then(function(result) {
    report(result.state);
  });
}
					

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
revoke 非标 Chrome 46 Edge 79 Firefox 51 Disabled
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.
47 — 51
IE 不支持 No Opera ? Safari 不支持 No WebView Android 46 Chrome Android 46 Firefox Android 51 Disabled
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.
47 — 51
Opera Android ? Safari iOS 不支持 No Samsung Internet Android 5.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

非标。预期跨浏览器支持较差。

用户必须明确启用此特征。

用户必须明确启用此特征。

元数据

  • 最后修改: