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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
---
title: Notification.permission
slug: Web/API/notification/permission
tags:
- API
- DOM
- Notifications
- Property
- Reference
translation_of: Web/API/Notification/permission
---
<p>{{APIRef("Web Notifications")}}</p>
<p>Die schreibgeschützte Berechtigungseigenschaft der Schnittstelle {{domxref ("Notificaton")}} gibt die aktuelle Berechtigung an, die der Benutzer für den aktuellen Ursprung zur Anzeige von Web-Benachrichtigungen erteilt hat.</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>Ein {{domxref ("DOMString")}} repräsentiert die aktuelle Berechtigung. Der Wert kann sein:</p>
<ul>
<li><code>granted</code>: Der Benutzer hat explizit die Berechtigung für den aktuellen Ursprung zur Anzeige von Systembenachrichtigungen erteilt.</li>
<li><code>denied</code>: Der Benutzer hat die Berechtigung für den aktuellen Ursprung explizit abgelehnt, um Systembenachrichtigungen anzuzeigen.</li>
<li><code>default</code>: Die Benutzerentscheidung ist unbekannt; In diesem Fall wird die Anwendung so tun, als ob die Erlaubnis verweigert wurde.</li>
</ul>
<h2 id="Beispiele">Beispiele</h2>
<p>Das folgende ziemlich ausführliche Snippet könnte verwendet werden, wenn Sie zuerst überprüfen möchten, ob Benachrichtigungen unterstützt werden, und prüfen Sie dann, ob für den aktuellen Ursprung die Erlaubnis für das Senden von Benachrichtigungen gewährt wurde, und fordern Sie dann bei Bedarf eine Genehmigung an, bevor Sie eine Benachrichtigung senden.</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="Spezifikationen">Spezifikationen</h2>
<table>
<tbody>
<tr>
<th scope="col">Spezifikation</th>
<th scope="col">Status</th>
<th scope="col">Kommentar</th>
</tr>
<tr>
<td>{{SpecName("Web Notifications","#dom-notification-permission","permission")}}</td>
<td>{{Spec2('Web Notifications')}}</td>
<td>Lebensstandard</td>
</tr>
</tbody>
</table>
<h2 id="Browserkombatibilität">Browserkombatibilität</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>Grundlegende Unterstützung</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>Vorhanden in den Arbeitskräften</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>
<p>Grundlegende Unterstützung</p>
</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>Vorhanden in den Arbeitskräften</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_Notizen">Firefox OS Notizen</h3>
<p id="Page(en-USdocsWebAPINotifications_API_Firefox_OS_notes)"><span style="color: #3b3c40; font-size: 14px; line-height: 1.5;">{{Page("/en-US/docs/Web/API/Notifications_API", "Firefox OS notes")}}</span></p>
<h3 id="Chrome_Notizen">Chrome Notizen</h3>
<p>{{Page("/en-US/docs/Web/API/Notifications_API", "Chrome notes")}}</p>
<h3 id="Safari_Notizen">Safari Notizen</h3>
<p>{{Page("/en-US/docs/Web/API/Notifications_API", "Safari notes")}}</p>
<h2 id="Siehe_auch">Siehe auch</h2>
<ul>
<li><a href="/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API">Verwenden der Benachrichtigungs-API</a></li>
<li>{{domxref("Permissions_API","Permissions API")}}</li>
</ul>
|