aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/notification/permission
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/notification/permission
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/notification/permission')
-rw-r--r--files/zh-cn/web/api/notification/permission/index.html179
1 files changed, 179 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/notification/permission/index.html b/files/zh-cn/web/api/notification/permission/index.html
new file mode 100644
index 0000000000..7cd16cf9d1
--- /dev/null
+++ b/files/zh-cn/web/api/notification/permission/index.html
@@ -0,0 +1,179 @@
+---
+title: Notification.permission
+slug: Web/API/notification/permission
+translation_of: Web/API/Notification/permission
+---
+<p>{{APIRef("Web Notifications")}}</p>
+
+<p><code>Notification 的只读属性 permission 用来表明用户是否允许当前域显示Web Notification. </code></p>
+
+<p>{{AvailableInWorkers}}</p>
+
+<h2 id="Syntax" name="Syntax">Syntax</h2>
+
+<pre class="syntaxbox">var <em>permission</em> = Notification.permission;</pre>
+
+<h3 id="Return_Value" name="Return_Value">Value</h3>
+
+<p>permission 的类型为 {{domxref("DOMString")}} . 该属性的可能值为:</p>
+
+<ul>
+ <li><code>granted</code>: 用户已经明确的授予了显示通知的权限。.</li>
+ <li><code>denied</code>: 用户已经明确的拒绝了显示通知的权限。</li>
+ <li><code>default</code>: 用户还未被询问是否授权; 这种情况下权限将视为 <code>denied</code>.</li>
+</ul>
+
+<h2 id="Examples">Examples</h2>
+
+<p>下面的代码片段详细的说明了,当你首次检查浏览器是否支持Notification,然后检查当前域是否被授予了发送Notification的权限,并且在发送一个通知前进行请求的用法.</p>
+
+<pre class="brush: js">function notifyMe() {
+ // Let's check if the browser supports notifications
+ if (!("Notification" in window)) {
+ console.log("This browser does not support desktop notification");
+ }
+
+ // Let's check whether notification permissions have alredy been granted
+ else if (Notification.permission === "granted") {
+ // If it's okay let's create a notification
+ var notification = new Notification("Hi there!");
+ }
+
+ // Otherwise, we need to ask the user for permission
+ else if (Notification.permission !== 'denied' || Notification.permission === "default") {
+ Notification.requestPermission(function (permission) {
+ // If the user accepts, let's create a notification
+ if (permission === "granted") {
+ var notification = new Notification("Hi there!");
+ }
+ });
+ }
+
+ // At last, if the user has denied notifications, and you
+ // want to be respectful there is no need to bother them any more.
+}</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table>
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName("Web Notifications","#dom-notification-permission","permission")}}</td>
+ <td>{{Spec2('Web Notifications')}}</td>
+ <td>Living standard</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<p>{{ CompatibilityTable() }}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>5 {{ property_prefix("webkit") }} (see notes)<br>
+ 22</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>4.0 {{ property_prefix("moz") }} (see notes)<br>
+ 22</td>
+ <td>{{ CompatNo() }}</td>
+ <td>25</td>
+ <td>6 (see notes)</td>
+ </tr>
+ <tr>
+ <td>Available in workers</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoDesktop("41.0")}}</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>Feature</th>
+ <th>Android</th>
+ <th>Android Webview</th>
+ <th>Edge</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Firefox OS</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ <th>Chrome for Android</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>
+ <p>{{CompatVersionUnknown}}</p>
+ </td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>4.0 {{ property_prefix("moz") }} (see notes)<br>
+ 22</td>
+ <td>1.0.1 {{ property_prefix("moz") }} (see notes)<br>
+ 1.2</td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatNo() }}</td>
+ <td>
+ <p>{{CompatVersionUnknown}}</p>
+ </td>
+ </tr>
+ <tr>
+ <td>Available in workers</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoMobile(41.0)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h3 id="Firefox_OS_notes">Firefox OS notes</h3>
+
+<p>{{Page("/en-US/docs/Web/API/Notifications_API", "Firefox OS notes")}}</p>
+
+<h3 id="Chrome_notes">Chrome notes</h3>
+
+<p>{{Page("/en-US/docs/Web/API/Notifications_API", "Chrome notes")}}</p>
+
+<h3 id="Safari_notes">Safari notes</h3>
+
+<p>{{Page("/en-US/docs/Web/API/Notifications_API", "Safari notes")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API">Using the Notifications API</a></li>
+ <li>{{domxref("Permissions_API","Permissions API")}}</li>
+</ul>