# ServiceWorkerGlobalScope.onnotificationclick (ok)

Các **ServiceWorkerGlobalScope.onnotificationclick** tài sản là phương thức thụ lý sự kiện được gọi bất cứ khi nào [`notificationclick`](https://translate.googleusercontent.com/translate_c?depth=1\&pto=aue\&rurl=translate.google.com.vn\&sl=en\&sp=nmt4\&tl=vi\&u=https://developer.mozilla.org/en-US/docs/Web/Events/notificationclick\&usg=ALkJrhi3pAxsSr8EGM7-fenZ6ZMDXbrGNg)sự kiện được gửi đi trên [`ServiceWorkerGlobalScope`](https://translate.googleusercontent.com/translate_c?depth=1\&pto=aue\&rurl=translate.google.com.vn\&sl=en\&sp=nmt4\&tl=vi\&u=https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope\&usg=ALkJrhjyevf84tPLjTNSKZj27ptuRQOrCw)đối tượng, đó là khi người dùng nhấp vào một thông báo hiển thị sinh ra bởi [`ServiceWorkerRegistration.showNotification()`](https://translate.googleusercontent.com/translate_c?depth=1\&pto=aue\&rurl=translate.google.com.vn\&sl=en\&sp=nmt4\&tl=vi\&u=https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification\&usg=ALkJrhiwiUkDCsz2u9Pv1vKzfwQyTaVCtQ).

Thông báo được tạo trên luồng chính hoặc trong các công nhân không phải là nhân viên phục vụ sử dụng hàm [`Notification()`](https://translate.googleusercontent.com/translate_c?depth=1\&pto=aue\&rurl=translate.google.com.vn\&sl=en\&sp=nmt4\&tl=vi\&u=https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification\&usg=ALkJrhhRn8v26vFfVVZZWdATLjNI0HWDLA)tạo thay vào đó sẽ nhận được một [`click`](https://translate.googleusercontent.com/translate_c?depth=1\&pto=aue\&rurl=translate.google.com.vn\&sl=en\&sp=nmt4\&tl=vi\&u=https://developer.mozilla.org/en-US/docs/Web/Events/click\&usg=ALkJrhj9ur_ek80kMeZUg0fEGhVoIRQxsA)sự kiện trên `Notification`chính đối tượng đó.

**Lưu ý** : Cố gắng tạo thông báo bên trong [`ServiceWorkerGlobalScope`](https://translate.googleusercontent.com/translate_c?depth=1\&pto=aue\&rurl=translate.google.com.vn\&sl=en\&sp=nmt4\&tl=vi\&u=https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope\&usg=ALkJrhjyevf84tPLjTNSKZj27ptuRQOrCw)bằng cách sử dụng hàm [`Notification()`](https://translate.googleusercontent.com/translate_c?depth=1\&pto=aue\&rurl=translate.google.com.vn\&sl=en\&sp=nmt4\&tl=vi\&u=https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification\&usg=ALkJrhhRn8v26vFfVVZZWdATLjNI0HWDLA)tạo sẽ gây ra lỗi.

### Cú pháp <a href="#syntax" id="syntax"></a>

```
ServiceWorkerGlobalScope.onnotificationclick = function(NotificationEvent) { ... };
```

### Thí dụ <a href="#example" id="example"></a>

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