PermissionStatus:change 事件
Baseline 2022Newly 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
接口的 change
事件在 PermissionStatus.state
属性发生更改时触发。
语法
在 addEventListener()
等方法中使用事件名称,或设置事件处理器属性。
js
addEventListener("change", (event) => {});
onchange = (event) => {};
事件类型
一个通用的 Event
。
示例
js
navigator.permissions
.query({ name: "geolocation" })
.then((permissionStatus) => {
console.log(`geolocation 权限状态为 ${permissionStatus.state}`);
permissionStatus.onchange = () => {
console.log(`geolocation 权限状态已更改为 ${permissionStatus.state}`);
};
});
规范
Specification |
---|
Permissions # dom-permissionstatus-onchange |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
change event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
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.