NotificationEvent:NotificationEvent() 构造函数
基线
广泛可用
自 2023年3月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。
Want more support for this feature? Tell us why.
备注: 此特性仅在 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 });
规范
| 规范 |
|---|
| Notifications API> # dom-notificationevent-notificationevent> |