ServiceWorkerGlobalScope:notificationclose 事件
注意:此功能僅在 Service Workers 中可用。
notificationclose 事件是 ServiceWorkerGlobalScope 介面的一部分,當用戶關閉由 ServiceWorkerRegistration.showNotification() 觸發的已顯示通知時,該事件會被觸發。
在主執行緒或非 Service Worker 的 Worker 中使用 Notification() 建構函式建立的通知,將會在 Notification 物件本身上接收一個 close 事件。
此事件不可取消,也不會冒泡。
語法
在諸如 addEventListener() 之類的方法中使用事件名稱,或設定事件處理程式屬性。
js
addEventListener("notificationclose", (event) => { })
onnotificationclose = (event) => { }
事件型別
一個 NotificationEvent。繼承自 ExtendableEvent 和 Event。
事件屬性
繼承自其祖先 ExtendableEvent 和 Event 的屬性.
NotificationEvent.notification只讀-
返回一個
Notification物件,表示被點選以觸發事件的通知。 NotificationEvent.action只讀-
返回使用者點選的通知按鈕的字串 ID。如果使用者點選了通知中的操作按鈕以外的區域,或者通知沒有按鈕,則此值為空字串。
示例
js
// Inside a service worker.
self.onnotificationclose = (event) => {
console.log("On notification close: ", event.notification.tag);
};
規範
| 規範 |
|---|
| Notifications API # dom-serviceworkerglobalscope-onnotificationclose |
瀏覽器相容性
載入中…