このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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月⁩.

メモ: この機能はサービスワーカー内でのみ利用可能です。

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

ブラウザーの互換性