From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/fr/web/api/notificationevent/index.html | 162 ++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 files/fr/web/api/notificationevent/index.html (limited to 'files/fr/web/api/notificationevent') diff --git a/files/fr/web/api/notificationevent/index.html b/files/fr/web/api/notificationevent/index.html new file mode 100644 index 0000000000..12d31e9481 --- /dev/null +++ b/files/fr/web/api/notificationevent/index.html @@ -0,0 +1,162 @@ +--- +title: NotificationEvent +slug: Web/API/NotificationEvent +tags: + - API + - Experimental + - Interface + - Reference + - ServiceWorker +translation_of: Web/API/NotificationEvent +--- +
{{APIRef("Service Workers API")}}{{SeeCompatTable}}
+ +

L'interface NotificationEvent représente un évènement de clic pour une notification et qui est dispatché vers le {{domxref("ServiceWorkerGlobalScope")}} d'un {{domxref("ServiceWorker")}}.

+ +

Cette interface hérite de l'interface {{domxref("ExtendableEvent")}}.

+ +

Constructeur

+ +
+
{{domxref("NotificationEvent.NotificationEvent()")}}
+
Cette méthode permet de créer un nouvel objet NotificationEvent.
+
+ +

Propriétés

+ +

Cet objet hérite de propriétés grâce à son ancêtre : {{domxref("Event")}}.

+ +
+
{{domxref("NotificationEvent.notification")}} {{readonlyInline}}
+
Cette propriété renvoie un objet {{domxref("Notification")}} représentant la notification sur laquelle on a cliqué pour déclencher l'évènement.
+
{{domxref("NotificationEvent.action")}} {{readonlyinline}}
+
Cette propriété renvoie une chaîne de caractères identifiant le bouton de la notification sur lequel l'utilisateur a cliqué. Cette valeur sera {{jsxref("undefined")}} si l'utilisateur a cliqué autre part que sur le bouton pour la notification ou si la notification ne possède pas de bouton.
+
+ +

Méthodes

+ +

Cet objet hérite de méthodes grâce à son parent {{domxref("ExtendableEvent")}}.

+ +
+
{{domxref("ExtendableEvent.waitUntil", "ExtendableEvent.waitUntil()")}}
+
+

Cette méthode allonge la durée de vie de l'évènement. Elle est conçue pour être appelée dans le gestionnaire d'évènement {{event("install")}} lors de l'installation (cf. {{domxref("ServiceWorkerRegistration.installing")}}) du worker et dans le gestionnaire d'évènement {{event("active")}} pour le worker actif (cf. {{domxref("ServiceWorkerRegistration.active")}}).

+
+
+ +

Exemples

+ +
self.addEventListener('notificationclick', function(event) {
+  console.log('Au clic sur la notification : ', event.notification.tag);
+  event.notification.close();
+
+  // On regarde ici si elle est déjà ouverte
+  // et si le focus est dessus
+  event.waitUntil(clients.matchAll({
+    type: "window"
+  }).then(function(clientList) {
+    for (var i = 0; i < clientList.length; i++) {
+      var client = clientList[i];
+      if (client.url == '/' && 'focus' in client)
+        return client.focus();
+    }
+    if (clients.openWindow)
+      return clients.openWindow('/');
+  }));
+});
+
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('Web Notifications','#notificationevent','NotificationEvent')}}{{Spec2('Web Notifications')}} 
+ +
+

Note : Cette interface est définie au sein de l'API Notifications, mais on y accède via {{domxref("ServiceWorkerGlobalScope")}}.

+
+ +

Compatibilité des navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support simple{{CompatChrome(42)}}{{CompatGeckoDesktop("44.0")}}[1]{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
action{{CompatChrome(48)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidWebview AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileChrome pour Android
Support simple{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("44.0")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatChrome(42)}}
action{{CompatNo}}{{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatChrome(48)}}
+
+ +

[1] Les service workers (ainsi que l'API Push) ont été désactivés dans l'édition Firefox 45 Extended Support Release (ESR).

-- cgit v1.2.3-54-g00ecf