Клиент: свойство url
Базовая линия Широко доступно
Эта функция хорошо зарекомендовала себя и работает на многих устройствах и версиях браузеров. Она доступна в браузерах с апреля 2018 года.
Примечание: Эта функция доступна только в Сервисных рабочих процессах.
Только для чтения url свойство интерфейса Client возвращает URL текущего клиента сервисного рабочего процесса.
Значение
Строка.
Примеры
self.addEventListener("notificationclick", (event) => {
console.log("On notification click: ", event.notification.tag);
event.notification.close();
// This looks to see if the current is already open and
// focuses if it is
event.waitUntil(
clients
.matchAll({
type: "window",
})
.then((clientList) => {
for (const client of clientList) {
if (client.url === "/" && "focus" in client) {
return client.focus();
}
}
if (clients.openWindow) {
return clients.openWindow("/");
}
}),
);
});
Спецификации
| Спецификация |
|---|
| Сервисные рабочие процессы # client-url |
Совместимость с браузерами
| Рабочий стол | Мобильные устройства | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox для Android | Opera Android | Safari на IOS | Samsung Internet | WebView Android | |
url |
40 | 17 | 44 | 27 | 11.1 | 40 | 44 | 27 | 11.3 | 4.0 | 40 |
© 2005–2024 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Client/url