diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/permissions_api/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/permissions_api/index.html')
-rw-r--r-- | files/zh-cn/web/api/permissions_api/index.html | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/permissions_api/index.html b/files/zh-cn/web/api/permissions_api/index.html new file mode 100644 index 0000000000..5c14434f15 --- /dev/null +++ b/files/zh-cn/web/api/permissions_api/index.html @@ -0,0 +1,94 @@ +--- +title: Permissions API +slug: Web/API/Permissions_API +tags: + - API + - Introduction + - NeedsTranslation + - Overview + - Permissions + - Permissions API + - TopicStub + - Web + - access +translation_of: Web/API/Permissions_API +--- +<p>{{DefaultAPISidebar("Permissions API")}}</p> + +<div class="summary"> +<p><span class="seoSummary">The <strong>Permissions API</strong> provides a consistent programmatic way to query the status of API permissions attributed to the current context. For example, the Permissions API can be used to determine if permission to access a particular API has been granted or denied.</span></p> +</div> + +<h2 id="Concepts_and_usage">Concepts and usage</h2> + +<p>Historically different APIs handle their own permissions inconsistently — for example the <a href="/en-US/docs/Web/API/Notifications_API">Notifications API</a> allows for explicit checking of permission status and requesting permission, whereas the <a href="/en-US/docs/Web/API/Geolocation">Geolocation API</a> doesn't (which causes problems if the user denied the initial permission request). The Permissions API provides the tools to allow developers to implement a better user experience as far as permissions are concerned.</p> + +<p>The <code>permissions</code> property has been made available on the {{domxref("Navigator")}} object, both in the standard browsing context and the worker context ({{domxref("WorkerNavigator")}} — so permission checks are available inside workers), and returns a {{domxref("Permissions")}} object that provides access to the Permissions API functionality.</p> + +<p>Once you have this object you can then perform permission-related tasks, for example querying a permission using the {{domxref("Permissions.query()")}} method to return a promise that resolves with the {{domxref("PermissionStatus")}} for a specific API.</p> + +<p>Not all APIs' permission statuses can be queried using the Permissions API. Notable APIs that are Permissions-aware include:</p> + +<ul> + <li><a href="/en-US/docs/Web/API/Clipboard_API">Clipboard API</a></li> + <li><a href="/en-US/docs/Web/API/Notifications_API">Notifications API</a></li> + <li><a href="/en-US/docs/Web/API/Push_API">Push API</a></li> + <li>Web MIDI API</li> +</ul> + +<p>More APIs will gain Permissions API support over time.</p> + +<h2 id="Examples">Examples</h2> + +<p>We have made a simple example available called Location Finder. You can <a href="https://chrisdavidmills.github.io/location-finder-permissions-api/">run the example live</a>, or <a href="https://github.com/chrisdavidmills/location-finder-permissions-api/tree/gh-pages">view the source code on Github</a>.</p> + +<p>Read more about how it works in our article <a href="/en-US/docs/Web/API/Permissions_API/Using_the_Permissions_API">Using the Permissions API</a>.</p> + +<h2 id="Interfaces">Interfaces</h2> + +<dl> + <dt>{{domxref("Navigator.permissions")}} and {{domxref("WorkerNavigator.permissions")}} {{readonlyinline}}</dt> + <dd>Provides access to the {{domxref("Permissions")}} object from the main context and worker context respectively.</dd> + <dt>{{domxref("Permissions")}}</dt> + <dd>Provides the core Permission API functionality, such as methods for querying and revoking permissions.</dd> + <dt>{{domxref("PermissionStatus")}}</dt> + <dd>Provides access to the current status of a permission, and an event handler to respond to changes in permission status.</dd> +</dl> + +<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')}}</td> + <td>{{Spec2('Permissions API')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> +<h3 id="Permissions_interface">Permissions interface</h3> + +<div> + + +<p>{{Compat("api.Permissions")}}</p> +</div> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Permissions_API/Using_the_Permissions_API">Using the Permissions API</a></li> + <li><a href="https://blog.addpipe.com/using-permissions-api-to-detect-getusermedia-responses/">Using the Permissions API to Detect How Often Users Allow or Deny Camera Access</a></li> + <li>{{DOMxRef("Notification.permission")}}</li> + <li><a href="/en-US/docs/Web/Privacy">Privacy, permissions, and information security</a></li> +</ul> |