NotificationEvent:NotificationEvent() 构造函数
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2023年3月.
备注: 此特性仅在 Service Worker 中可用。
NotificationEvent() 构造函数创建一个新的 NotificationEvent 对象。
语法
js
new NotificationEvent(type, options)
参数
type-
一个表示事件名称的字符串。它区分大小写,浏览器使用时将其设置为
notificationclick或notificationclose。 options-
一个对象,除了
ExtendableEvent()中定义的属性外,还具有以下属性:notification-
一个
Notification对象,用作触发事件的通知。 action可选-
一个与通知关联的操作。默认为
""。
返回值
一个新的 NotificationEvent() 对象。
示例
js
const n = new Notification("Hello");
const myNotificationEvent = new NotificationEvent(type, { notification: n });
规范
| Specification |
|---|
| Notifications API> # dom-notificationevent-notificationevent> |
浏览器兼容性
Loading…