NotificationEvent:action 屬性
注意:此功能僅在 Service Workers 中可用。
action 是 NotificationEvent 介面的一個只讀屬性,它返回使用者點選的通知按鈕的字串 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 |
瀏覽器相容性
載入中…