blob: 59a142023bce848cdda5ed3b56ee5b3ab5e28960 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
---
title: Permissions
slug: Web/API/Permissions
translation_of: Web/API/Permissions
---
<p>{{APIRef("Permissions API")}}{{SeeCompatTable}}</p>
<p><a href="Permissions_API">Permissions API</a>的Permissions接口提供核心PermissionAPI功能,例如查询和撤消权限的方法。</p>
<h2 id="方法">方法</h2>
<dl>
<dt>{{domxref("Permissions.query","Permissions.query()")}}</dt>
<dd>返回给定API的用户权限状态。</dd>
<dt>{{domxref("Permissions.request","Permissions.request()")}}</dt>
<dd>
<p>请求使用给定API的权限,<span style="font-size: 1rem; letter-spacing: -0.00278rem;">目前此功能尚未在任何浏览器中被支持。</span></p>
</dd>
<dt>{{domxref("Permissions.requestAll","Permissions.requestAll()")}}</dt>
<dd>请求使用一组给定API的权限。目前此功能<span style="font-size: 1rem; letter-spacing: -0.00278rem;">尚</span>未在任何浏览器中被支持。</dd>
<dt>{{domxref("Permissions.revoke","Permissions.revoke()")}}</dt>
<dd>返回撤消当前在给定API上设置的权限。</dd>
</dl>
<h2 id="Example">Example</h2>
<pre class="brush: js">navigator.permissions.query({name:'geolocation'}).then(function(result) {
if (result.state === 'granted') {
showLocalNewsWithGeolocation();
} else if (result.state === 'prompt') {
showButtonToEnableLocalNews();
}
// 如果没有此权限则不什么也做
});</pre>
<h2 id="Specification">Specification</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName("Permissions API","#permissions-interface", "Permissions")}}</td>
<td>{{Spec2("Permissions API")}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_Support">Browser Support</h2>
<div>
<p>{{Compat("api.Permissions")}}</p>
</div>
|