aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/api/notification/close/index.md
diff options
context:
space:
mode:
Diffstat (limited to 'files/fr/web/api/notification/close/index.md')
-rw-r--r--files/fr/web/api/notification/close/index.md80
1 files changed, 80 insertions, 0 deletions
diff --git a/files/fr/web/api/notification/close/index.md b/files/fr/web/api/notification/close/index.md
new file mode 100644
index 0000000000..359bf36dda
--- /dev/null
+++ b/files/fr/web/api/notification/close/index.md
@@ -0,0 +1,80 @@
+---
+title: Notification.close()
+slug: Web/API/notification/close
+tags:
+ - API
+ - API Notifications
+ - Méthode
+ - Notification
+ - Notifications
+ - Reference
+ - close
+ - fermeture
+translation_of: Web/API/Notification/close
+---
+<p>{{APIRef("Web Notifications")}}{{AvailableInWorkers}}{{securecontext_header}}</p>
+
+<p>La méthode <code>close()</code> de l'interface {{domxref("Notification")}} est utilisée pour fermer / supprimer une notification précédemment affichée.</p>
+
+<div class="note">
+<p><strong>Note:</strong> Cette API ne doit pas être utilisée uniquement pour supprimer la notification de l'écran après un délai fixe, car cette méthode supprimera également la notification de toute barre de notification, empêchant ainsi les utilisateurs d'interagir avec elle après son affichage initial. Une utilisation valable de cette API serait de supprimer une notification qui n'est plus pertinente (par exemple, l'utilisateur a déjà lu la notification sur la page Web dans le cas d'une application de messagerie ou la chanson suivante est déjà en cours de lecture dans une application musicale).</p>
+</div>
+
+<h2 id="Syntaxe">Syntaxe</h2>
+
+<pre class="syntaxbox">Notification.close()</pre>
+
+<h3 id="Paramètres">Paramètres</h3>
+
+<p>Aucun.</p>
+
+<h3 id="Returns">Returns</h3>
+
+<p>Void.</p>
+
+<h2 id="Exemples">Exemples</h2>
+
+<p>Dans l'extrait de code suivant, nous avons une simple fonction qui, lorsqu'elle est appelée, crée un objet <code>options</code>, puis de celui-ci une nouvelle notification. À la fin de la fonction, elle appelle également <code>close()</code> dans une fonction {{domxref ("EventTarget.addEventListener", "addEventListener ()")}} pour supprimer la notification lorsque le contenu pertinent a été lu sur la page Web.</p>
+
+<pre class="brush:js">function spawnNotification(theBody, theIcon, theTitle) {
+ const options = {
+ body: theBody,
+ icon: theIcon
+ }
+
+ const n = new Notification(theTitle, options)
+ document.addEventListener('visibilitychange', () =&gt; {
+ if (document.visibilityState === 'visible') {
+ // The tab has become visible so clear the now-stale Notification.
+ n.close()
+ }
+ })
+}
+</pre>
+
+<h2 id="Spécifications">Spécifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Spécification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Web Notifications')}}</td>
+ <td>{{Spec2('Web Notifications')}}</td>
+ <td>Living standard</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>
+
+<p>{{Compat("api.Notification.close")}}</p>
+
+<h2 id="Voir_également">Voir également</h2>
+
+<ul>
+ <li><a href="/fr/docs/Web/API/Notifications_API/Using_the_Notifications_API">Utilisation de l'API Notifications</a></li>
+</ul>