From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../fr/web/api/notification/permission/index.html | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 files/fr/web/api/notification/permission/index.html (limited to 'files/fr/web/api/notification/permission/index.html') diff --git a/files/fr/web/api/notification/permission/index.html b/files/fr/web/api/notification/permission/index.html new file mode 100644 index 0000000000..dc74126304 --- /dev/null +++ b/files/fr/web/api/notification/permission/index.html @@ -0,0 +1,95 @@ +--- +title: Notification.permission +slug: Web/API/notification/permission +tags: + - API + - API Notifications + - Notification + - Notifications + - Propriété + - Reference +translation_of: Web/API/Notification/permission +--- +

{{APIRef("Web Notifications")}}{{AvailableInWorkers}}{{securecontext_header}}

+ +

La propriété en lecture seule permission de l'interface {{domxref ("Notification")}} indique l'autorisation actuelle accordée par l'utilisateur à l'origine actuelle pour afficher des notifications.

+ +

Syntaxe

+ +
Notification.permission
+ +

Valeur

+ +

Une {{domxref("DOMString")}} représentant l'autorisation actuelle. La valeur peut être:

+ + + +

Exemples

+ +

L'extrait suivant peut être utilisé si vous souhaitez d'abord vérifier si les notifications sont prises en charge, puis vérifier si l'autorisation a été accordée pour l'origine actuelle pour envoyer des notifications, puis demander l'autorisation si nécessaire, avant d'envoyer une notification.

+ +
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
+    const notification = new Notification('Hi there!')
+  }
+
+  // Otherwise, we need to ask the user for permission
+  else if (
+    Notification.permission !== 'denied' ||
+    Notification.permission === 'default'
+  ) {
+    Notification.requestPermission((permission) => {
+      // If the user accepts, let's create a notification
+      if (permission === 'granted') {
+        const 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.
+}
+
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaire
{{SpecName("Web Notifications","#dom-notification-permission","permission")}}{{Spec2('Web Notifications')}}Living standard
+ +

Compatibilité des navigateurs

+ + + +

{{Compat("api.Notification.permission")}}

+ +

Voir également

+ + -- cgit v1.2.3-54-g00ecf