Cette page a été traduite à partir de l'anglais par la communauté. Vous pouvez contribuer en rejoignant la communauté francophone sur MDN Web Docs.

View in English Always switch to English

Client.url

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨avril 2018⁩.

Expérimental: Il s'agit d'une technologie expérimentale.
Vérifiez attentivement le tableau de compatibilité des navigateurs avant de l'utiliser en production.

La propriété url (lecture seule) de l'interface Client retourne l'url du service worker client courant.

Syntaxe

js
var clientUrl = Client.url;

Valeur de retour

Valeur de type USVString.

Exemple

js
self.addEventListener("notificationclick", function (event) {
  console.log("Au click de notification : ", event.notification.tag);
  event.notification.close();

  // Vérification pour savoir si l'évenement est ouvert et
  // se focalise dessus si c'est le cas
  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

Specification
Service Workers
# client-url

Compatibilité des navigateurs