NotificationEvent:action 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

注意:此功能僅在 Service Workers 中可用。

actionNotificationEvent 介面的一個只讀屬性,它返回使用者點選的通知按鈕的字串 ID。如果使用者點選了通知中除操作按鈕以外的其他位置,或者通知沒有按鈕,則此值返回一個空字串。通知 ID 在建立通知時透過 actions 陣列屬性設定,除非替換通知,否則無法修改。

字串。

示例

js
self.registration.showNotification("New articles available", {
  actions: [{ action: "get", title: "Get now." }],
});

self.addEventListener("notificationclick", (event) => {
  event.notification.close();
  if (event.action === "get") {
    synchronizeReader();
  } else {
    clients.openWindow("/reader");
  }
});

規範

規範
Notifications API
# dom-notification-actions

瀏覽器相容性