PermissionStatus

这是 实验性技术
检查 浏览器兼容性表格 在生产中使用这之前。

PermissionStatus interface of the 权限 API provides the state of an object and an event handler for monitoring changes to said state.

特性

PermissionStatus.state 只读
Returns the state of a requested permission; one of 'granted' , 'denied' ,或 'prompt' .
PermissionStatus.status 只读
Returns the state of a requested permission; one of 'granted' , 'denied' ,或 'prompt' . Later versions of the specification replace this with PermissionStatus.state .

Event Handler

PermissionStatus.onchange
An event called whenever PermissionStatus.status 改变。

范例

navigator.permissions.query({name:'geolocation'}).then(function(permissionStatus) {
  console.log('geolocation permission status is ', permissionStatus.state);
  permissionStatus.onchange = function() {
    console.log('geolocation permission status has changed to ', this.state);
  };
});
					

规范

规范 状态 Comment
Permissions
The definition of 'PermissionStatus' in that specification.
工作草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
PermissionStatus
Chrome 43 Edge 79 Firefox 46 IE No Opera Yes Safari No WebView Android No Chrome Android 43 Firefox Android 46 Opera Android Yes Safari iOS No Samsung Internet Android 4.0
onchange
Chrome 43 Edge 79 Firefox 46 IE No Opera Yes Safari No WebView Android No Chrome Android 43 Firefox Android 46 Opera Android Yes Safari iOS No Samsung Internet Android 4.0
state
Chrome 44
44
不支持 43 — 44
Alternate Name
Alternate Name Uses the non-standard name: status
Edge 79 Firefox 46 IE No Opera Yes Safari No WebView Android No Chrome Android 44
44
不支持 43 — 44
Alternate Name
Alternate Name Uses the non-standard name: status
Firefox Android 46 Opera Android Yes Safari iOS No Samsung Internet Android 4.0

图例

完整支持
完整支持
不支持
不支持
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
使用非标名称。