DOM

インターフェイス

NotificationEvent インターフェイス

  編集:2022.04.07 by T.A.

MS(en-US)

onnotificationclick ハンドラーに渡されるパラメーター。NotificationEvent インターフェースは、ServiceWorkerServiceWorkerGlobalScope でディスパッチされる通知クリックイベントを表します。

このインターフェースは、ExtendableEventインターフェースを継承します。

コンストラクター
new NotificationEvent()
新しい NotificationEvent オブジェクトを作成します。
プロパティ

祖先である Event からプロパティを継承します。

NotificationEvent.notification 読取専用
イベントを発生させるためにクリックされた通知を表す Notification オブジェクトを返します。
NotificationEvent.action 読取専用
ユーザーがクリックした通知ボタンの文字列 ID を返します。ユーザーがアクション ボタン以外の場所で通知をクリックした場合、この値は空の文字列を返します。または、通知にボタンがありません。
メソッド

親である ExtendableEvent からメソッドを継承します。

ExtendableEvent.waitUntil()
イベントの存続期間を延長します。作業が進行中であることをブラウザに通知します。
self.addEventListener('notificationclick', function(event) {
  console.log('On notification click: ', event.notification.tag);
  event.notification.close();

  // This looks to see if the current is already open and
  // focuses if it is
  event.waitUntil(clients.matchAll({
    type: "window"
  }).then(function(clientList) {
    for (var i = 0; i < clientList.length; i++) {
      var client = clientList[i];
      if (client.url == '/' && 'focus' in client)
        return client.focus();
    }
    if (clients.openWindow)
      return clients.openWindow('/');
  }));
});

テスト
HTML:

ここに表示
スクリプト組み込み:



スクリプト:


スクリプト:



表示内容:
表示内容: