ServiceWorkerGlobalScope: notificationclick event

notificationclick 이벤트는 ServiceWorkerRegistration.showNotification() 에 의해 발생한 시스템 notification 이 클릭되었음을 나타내기 위해 발생된다.

No
Cancelable No
Interface NotificationEvent
Event handler onnotificationclick

Examples

addEventListener 메소드 내에서 notificationclick 이벤트를 사용할 수 있다:

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('/');
  }));
});

또는 onnotificationclick 이벤트 핸들러 속성을 사용할 수 있다:

self.onnotificationclick = 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('/');
  }));
};

Specifications

Specification Status
Notifications API
The definition of 'onnotificationclick' in that specification.
Living Standard

Browser compatibility

BCD tables only load in the browser

See also