NotificationEvent: свойство notification
Ограниченная доступность
Эта функция не является базовой, так как она не работает в некоторых из самых широко используемых браузеров.
Примечание: Эта функция доступна только в Service Workers.
Только для чтения свойство notification интерфейса NotificationEvent возвращает экземпляр Notification, на который был нажат для запуска события. Notification предоставляет доступ только для чтения к многим свойствам, которые были установлены во время создания уведомления, таким как tag и data атрибуты, которые позволяют хранить информацию для последующего использования в событии notificationclick.
Значение
Объект Notification.
Примеры
self.addEventListener("notificationclick", (event) => {
console.log("On notification click");
// Data can be attached to the notification so that you
// can process it in the notificationclick handler.
console.log(`Notification Tag: ${event.notification.tag}`);
console.log(`Notification Data: ${event.notification.data}`);
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("/");
}),
);
});
Спецификации
Совместимость с браузерами
| Рабочий стол | Мобильные устройства | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari на IOS | Samsung Internet | WebView Android | |
notification |
42 | 17 | 44 | 37 | Нет | 42 | 44 | 37 | Нет | 4.0 | Нет |
© 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/NotificationEvent/notification