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 |
浏览器兼容性
加载中…