ServiceWorkerGlobalScope:notificationclose 事件
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
备注: 此特性仅在 Service Worker 中可用。
ServiceWorkerGlobalScope 接口的 notificationclose 事件在用户关闭由 ServiceWorkerRegistration.showNotification() 方法生成的显示的通知时触发。
在主线程或非 Service Worker 线程中使用 Notification() 构造函数创建的通知则将在 Notification 对象本身触发 close 事件。
此事件不可取消且不会冒泡。
语法
在 addEventListener() 等方法中使用事件名称,或设置事件处理器属性。
js
addEventListener("notificationclose", (event) => {});
onnotificationclose = (event) => {};
事件类型
一个 NotificationEvent。继承自 ExtendableEvent 和 Event。
事件属性
从其祖先 ExtendableEvent 和 Event 继承属性。
NotificationEvent.notification只读-
返回一个
Notification对象,表示单击而触发事件的通知。 NotificationEvent.action只读-
返回用户单击的通知按钮的字符串 ID。如果用户单击通知的操作按钮以外的部分,或者通知没有按钮,则此值返回空字符串。
示例
js
// 在 service worker 内部。
self.onnotificationclose = (event) => {
console.log("当关闭通知时:", event.notification.tag);
};
规范
| Specification |
|---|
| Notifications API> # dom-serviceworkerglobalscope-onnotificationclose> |
浏览器兼容性
Loading…