PermissionStatus:state 属性
Baseline 2022
Newly available
Since September 2022, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
备注: 此特性在 Web Worker 中可用。
PermissionStatus
接口的 state
只读属性返回所请求权限的状态。此属性返回 'granted'
、'denied'
或 'prompt'
之一。
值
示例
js
navigator.permissions
.query({ name: "geolocation" })
.then((permissionStatus) => {
console.log(`geolocation 权限状态为 ${permissionStatus.state}`);
permissionStatus.onchange = () => {
console.log(`geolocation 权限状态已更改为 ${permissionStatus.state}`);
};
});
规范
Specification |
---|
Permissions # dom-permissionstatus-state |
浏览器兼容性
BCD tables only load in the browser