[Go to site: main page, start]

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

View in English Always switch to English

NotificationEvent: NotificationEvent() コンストラクター

Baseline 広く利用可能

この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。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 });

仕様書

仕様書
Notifications API
# dom-notificationevent-notificationevent

ブラウザーの互換性