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/clients/openwindow/index.html | 131 +++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 files/fr/web/api/clients/openwindow/index.html (limited to 'files/fr/web/api/clients/openwindow') diff --git a/files/fr/web/api/clients/openwindow/index.html b/files/fr/web/api/clients/openwindow/index.html new file mode 100644 index 0000000000..906953237a --- /dev/null +++ b/files/fr/web/api/clients/openwindow/index.html @@ -0,0 +1,131 @@ +--- +title: Clients.openWindow() +slug: Web/API/Clients/openWindow +translation_of: Web/API/Clients/openWindow +--- +

{{SeeCompatTable}}{{APIRef("Service Workers API")}}

+ +

La méthode openWindow() de l'interface {{domxref("Clients")}} crée un nouveau niveau de contexte de navigation et charge une URL donnée. Si le script d'origine n'a pas la permission d'ouvrir une popup,   openWindow() lèvera une InvalidAccessError.

+ +

Dans Firefox, une méthode est authorisée d'ouvrir une popup seulement lorsqu'elle est appelée à la suite d'un click sur une notification.

+ +

Syntaxe

+ +
ServiceWorkerClients.openWindow(url).then(function(WindowClient) {
+  // Faire quelque chose avec le WindowClient
+});
+ +

Paramètres

+ +
+
url
+
Une {{domxref("USVString")}} représentant l'URL que le client veut ouvrir dans une nouvelle fenêtre. Généralement, cette valeur doit être une URL de la même  origine que le script d'origine.
+
+ +

Valeur de retour

+ +
+
Une {{jsxref("Promise")}} qui résoud un objet {{domxref("WindowClient")}} si l'URL est de la même origine que le service worker, et {{Glossary("null", "null value")}} sinon.
+
+ +

Exemples

+ +
// Quand l'utilisateur click sur une notification, focus sur la fenêtre si elle existe,
+// ou ouvre en une autre.
+onotificationclick = function(event) {
+  var found = false;
+  clients.matchAll().then(function(clients) {
+    for (i = 0; i < clients.length; i++) {
+      if (clients[i].url === event.data.url) {
+        // La fenêtre existe, focus dessus.
+        found = true;
+        clients[i].focus();
+        break;
+      }
+    }
+    if (!found) {
+      // Crée une nouvelle fenêtre
+      clients.openWindow(event.data.url).then(function(windowClient) {
+        // Faire quelque chose avec le WindowClient
+      });
+    }
+  });
+};
+
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationStatutCommentaire
{{SpecName('Service Workers', '#clients', 'Clients')}}{{Spec2('Service Workers')}}Définition initiale
+ +

Compatibilité des navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support de base{{CompatChrome(42.0)}} [1]{{ CompatGeckoDesktop("45.0") }}{{CompatNo}}{{CompatUnknown}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidAndroid WebviewFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari MobileChrome for Android
Support de base{{CompatNo}}{{CompatNo}}{{ CompatGeckoMobile("45.0") }}{{ CompatVersionUnknown }}{{CompatNo}}{{CompatUnknown}}{{CompatNo}}{{CompatChrome(40.0)}} [1]
+
+ + -- cgit v1.2.3-54-g00ecf