aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/api/client/url/index.md
blob: c9369370e24e390d7277a9524a52e624ea86b173 (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
---
title: Client.url
slug: Web/API/Client/url
tags:
  - API
  - Client
  - Experimental
  - Property
  - Reference
  - ServiceWorkers
  - URL
translation_of: Web/API/Client/url
---
{{SeeCompatTable}}{{APIRef("Service Workers API")}}La propriété **`url`** (lecture seule) de l'interface {{domxref("Client")}} retourne l'url du service worker client courant.

## Syntaxe

```js
var clientUrl = Client.url;
```

### Valeur de retour

Valeur de type {{domxref("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

| Spécification                                                            | Statut                               | Commentaire         |
| ------------------------------------------------------------------------ | ------------------------------------ | ------------------- |
| {{SpecName('Service Workers', '#client-url', 'url')}} | {{Spec2('Service Workers')}} | Défintion initiale. |

## Compatibilité des navigateurs

{{Compat("api.Client.url")}}