W3cubDocs

/Web APIs

NotificationEvent: NotificationEvent() constructor

The NotificationEvent() constructor creates a new NotificationEvent object.

Syntax

js

new NotificationEvent(type, options)

Parameters

type

A string with the name of the event. It is case-sensitive and browsers set it to notificationclick or notificationclose.

options

An object that, in addition of the properties defined in ExtendableEvent(), can have the following properties:

notification

A Notification object to be used as the notification the event is dispatched on.

action Optional

An action associated with the notification. It defaults to "".

Return value

A new NotificationEvent() object.

Examples

js

const n = new Notification("Hello");
const myNotificationEvent = new NotificationEvent(type, { notification: n });

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
NotificationEvent 42 17 44 No 37
16Supported on macOS 13 and later
No 42 44 37 16.4 4.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/NotificationEvent/NotificationEvent