aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/navigator/permissions/index.html
blob: bd4510a159b2989cdfba6a6c0c0e600994c9d104 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
title: Navigator.permissions
slug: Web/API/Navigator/permissions
tags:
  - API
  - Permissions
  - 属性
translation_of: Web/API/Navigator/permissions
---
<p>{{APIRef("HTML DOM")}}{{SeeCompatTable}}</p>

<p><code><strong>permissions</strong></code> 是 <code><strong>Navigator</strong></code> 读属性,返回一个可用于查询或更新某些APIs(由<a href="/en-US/docs/Web/API/Permissions_API">Permissions API</a>覆盖)的权限状态的对象。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><em>permissionsObj</em> = <em>globalObj</em>.navigator.permissions
</pre>

<h2 id="值"></h2>

<p>一个 {{domxref("Permissions")}} 对象。</p>

<h2 id="例子">例子</h2>

<pre class="brush: js">navigator.permissions.query({name:'geolocation'}).then(function(result) {
  if (result.state === 'granted') {
    showMap();
  } else if (result.state === 'prompt') {
    showButtonToEnableMap();
  }
  // 如果被拒绝,请不要做任何操作。
});
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">备注</th>
  </tr>
  <tr>
   <td>{{SpecName('Permissions API')}}</td>
   <td>{{Spec2('Permissions API')}}</td>
   <td>初始化定义</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器支持">浏览器支持</h2>

<div>{{ CompatibilityTable() }}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>功能</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>基础支持</td>
   <td>{{CompatChrome(43.0)}}</td>
   <td>{{CompatGeckoDesktop(46)}}</td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatUnknown()}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>功能</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>基础支持</td>
   <td>{{CompatNo()}}</td>
   <td>{{CompatChrome(43.0)}}</td>
   <td>{{CompatGeckoMobile(46)}}</td>
   <td>{{CompatUnknown()}}<sup>[1]</sup></td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatUnknown()}}</td>
   <td>{{CompatChrome(43.0)}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Firefox OS 现在采用自己的具有特殊工作方式的 Permissions API:参见  <a href="/en-US/docs/Web/API/Permissions_API_(Firefox_OS)">Permissions API (Firefox OS)</a>.</p>

<h2 id="See_also" name="See_also">参见</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/Permissions_API">Permissions API</a></li>
 <li>{{domxref("Navigator")}}</li>
</ul>