aboutsummaryrefslogtreecommitdiff
path: root/files/fr/mozilla/add-ons/webextensions/api/notifications/onshown/index.html
blob: 3514c20062676e7e5825af99e608cdea4abe5876 (plain)
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
---
title: notifications.onShown
slug: Mozilla/Add-ons/WebExtensions/API/notifications/onShown
tags:
  - API
  - Add-ons
  - Event
  - Extensions
  - Reference
  - WebExtensions
  - events
  - onShown
translation_of: Mozilla/Add-ons/WebExtensions/API/notifications/onShown
---
<div>{{AddonSidebar()}}</div>

<p>Lancé immédiatement après l'affichage d'une notification.</p>

<h2 id="Syntaxe">Syntaxe</h2>

<pre class="brush: js">browser.notifications.onShown.addListener(listener)
browser.notifications.onShown.removeListener(listener)
browser.notifications.onShown.hasListener(listener)
</pre>

<p>Les événements ont trois fonctions :</p>

<dl>
 <dt><code>addListener(callback)</code></dt>
 <dd>Ajoute un écouteur à cet événement.</dd>
 <dt><code>removeListener(listener)</code></dt>
 <dd>Arrêtez d'écouter cet événement. L'argument <code>listener</code> est l'écouteur à supprimer.</dd>
 <dt><code>hasListener(listener)</code></dt>
 <dd>Vérifiez si <code>listener</code> est enregistré pour cet événement. Renvoie <code>true</code>s'il écoute, sinon <code>false</code>.</dd>
</dl>

<h2 id="syntaxe_addListener">syntaxe addListener</h2>

<h3 id="Paramètres">Paramètres</h3>

<dl>
 <dt><code>callback</code></dt>
 <dd>
 <p>Fonction qui sera appelée lorsque cet événement se produit. La fonction recevra les arguments suivants :</p>

 <dl>
  <dt><code>notificationId</code></dt>
  <dd><code>string</code>. ID de la notification qui a été affichée.</dd>
 </dl>
 </dd>
</dl>

<h2 id="Compatibilité_du_navigateur">Compatibilité du navigateur</h2>

<p>{{Compat("webextensions.api.notifications.onShown")}}</p>

<h2 id="Exemples">Exemples</h2>

<p>Ajoutez un écouteur à l'événement {{WebExtAPIRef("notifications.onShown")}} et consignez ses détails :</p>

<pre class="brush: js">function logShown(itemId) {
  console.log(`shown: ${itemId}`);
  browser.notifications.getAll().then((all) =&gt; {
    console.log(all[itemId]);
  })
}

browser.notifications.onShown.addListener(logShown);</pre>

<p>{{WebExtExamples}}</p>

<div class="note"><p><strong>Note :</strong></p>

<p>Cette API est basée sur l'API Chromium <a href="https://developer.chrome.com/extensions/notifications"><code>chrome.notifications</code></a>.</p>
</div>