这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
Permissions.query()
方法在
权限
interface returns the state of a user permission on the global scope.
navigator.permissions.query(PermissionDescriptor).then(function(permissionStatus) { ... })
PermissionDescriptor
query
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. An up-to-date list of permission names can be found in the spec under the
PermissionName enum
, but bear in mind that the actual permissions supported by browsers is currently much smaller than this. Firefox for example currently supports
geolocation
,
notifications
,
push
,和
persistent-storage
(see our
Permissions.webidl
file
).
userVisibleOnly
: (Push only, not supported in Firefox — see the Browser Support 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
解析为
PermissionStatus
对象。
| 异常 | 解释 |
|---|---|
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
).
|
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.
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
权限
The definition of 'query()' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
query
|
Chrome 43 | Edge 79 | Firefox 46 | IE 不支持 No | Opera Yes | Safari 不支持 No | WebView Android 43 | Chrome Android 43 | Firefox Android 46 | Opera Android Yes | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
完整支持
不支持