1. 開発者向けのウェブ技術
  2. Web API
  3. NotificationEvent
  4. notification

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

View in English Always switch to English

NotificationEvent: notification プロパティ

利用可能性は限定的

この機能はベースラインではありません。最も広く使用されているブラウザーの一部で動作しません。

Want more support for this feature? Tell us why.

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

notificationNotificationEvent インターフェイスの読み取り専用プロパティで、クリックされてイベントを発行した Notification のインスタンスを返します。 Notificationtagdata 属性など、 Notification のインスタンス化時に設定された多くのプロパティへの読み取り専用アクセスを提供しており、あとで notificationclick イベントで使用するための情報を保存することができます。

返値

Notification オブジェクト。

js
self.addEventListener("notificationclick", (event) => {
 console.log("On notification click");
 // 通知にデータを添付することで、notificationclick ハンドラーで
 // 処理することができる
 console.log(`通知タグ: ${event.notification.tag}`);
 console.log(`通知データ: ${event.notification.data}`);
 event.notification.close();
 // これは、すでに開いているかどうかを調べて、開いている場合は
 // フォーカスする
 event.waitUntil(
 clients
 .matchAll({
 type: "window",
 })
 .then((clientList) => {
 for (const client of clientList) {
 if (client.url === "/" && "focus" in client) return client.focus();
 }
 if (clients.openWindow) return clients.openWindow("/");
 }),
 );
});

仕様書

仕様書
Notifications API
# dom-notificationevent-notification

ブラウザーの互換性

MDN の改良に協力

協力方法を知る

このページは MDN の貢献者によって に最終更新されました。

AltStyle によって変換されたページ (->オリジナル) /