Returns the string ID of the notification button the user clicked. This value returns an empty string if the user clicked the notification somewhere other than an action button, or the notification does not have a button. The notification id is set during the creation of the Notification via the actions array attribute and can't be modified unless the notification is replaced.

返回

A DOMString 对象。

范例

self.registration.showNotification("New articles available", {
  actions: [{action: "get", title: "Get now."}]
});
self.addEventListener('notificationclick', function(event) {
  event.notification.close();
  if (event.action === 'get') {
    synchronizeReader();
  } else {
    clients.openWindow("/reader");
  }
}, false);
					

规范

规范 状态 注释
Notifications API
The definition of 'action' in that specification.
实时标准 Living standard.

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
action Chrome 48 Edge ≤18 Firefox 44
44
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE ? Opera No Safari ? WebView Android No Chrome Android 48 Firefox Android 44 Opera Android No Safari iOS ? Samsung Internet Android 5.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

元数据

  • 最后修改: