NotificationEvent:NotificationEvent() 构造函数
备注: 此特性仅在 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 Standard # dom-notificationevent-notificationevent |
浏览器兼容性
BCD tables only load in the browser