NotificationAction

注意: 此特征可用于 Web 工作者 .

Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers .

NotificationAction interface of the Notifications API is used to represent action buttons the user can click to interact with notifications. These buttons' appearance and specific functionality vary across platforms but generally they provide a way to asynchronously show actions to the user in a notification.

特性

实例特性

These properties are available only on instances of the Notification 对象。

NotificationAction.action 只读
The name of the action, which can be used to identify the clicked action similar to input names .
NotificationAction.title 只读
The string describing the action that is displayed to the user.
NotificationAction.icon 只读
The URL of the image used to represent the notification when there is not enough space to display the notification itself.

范例

Notifications can fire notificationclick events on the ServiceWorkerGlobalScope .

Here a service worker shows a notification with a single "Archive" action, allowing users to perform this common task from the notification without having to open the website. The user can also click the main body of the notification to open their inbox instead.

self.registration.showNotification("New mail from Alice", {
  actions: [
    {
      action: 'archive',
      title: 'Archive'
    }
  ]
});
self.addEventListener('notificationclick', function(event) {
  event.notification.close();
  if (event.action === 'archive') {
    // Archive action was clicked
    archiveEmail();
  } else {
    // Main body of notification was clicked
    clients.openWindow('/inbox');
  }
}, false);
					

规范

规范 状态 Comment
Notifications API 实时标准 Living standard

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Notification Chrome 22
22
Before Chrome 22, the support for notification followed an old prefixed version of the specification and used the navigator.webkitNotifications object to instantiate a new notification. Before Chrome 32, Notification.permission was not supported. Before Chrome 42, service worker additions were not supported. Starting in Chrome 49, notifications do not work in incognito mode.
5
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 14 Firefox 22
22
4
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE No Opera 25 Safari 6 WebView Android No Chrome Android Yes Firefox Android 22
22
4
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Opera Android Yes Safari iOS No Samsung Internet Android Yes
Notification() 构造函数 Chrome 22
22
5
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge ≤18 Firefox 22
22
4
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE No Opera 25 Safari 6 WebView Android No Chrome Android Yes Firefox Android 22
22
4
Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android Yes Safari iOS No Samsung Internet Android Yes
actions Chrome 53 Edge 18 Firefox No IE No Opera 39 Safari ? WebView Android No Chrome Android 53 Firefox Android No Opera Android 41 Safari iOS No Samsung Internet Android 6.0
badge Chrome 53 Edge 18 Firefox No IE No Opera 39 Safari ? WebView Android No Chrome Android 53 Firefox Android No Opera Android 41 Safari iOS No Samsung Internet Android 6.0
body Chrome Yes Edge 14 Firefox Yes IE No Opera Yes Safari Yes WebView Android No Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS No Samsung Internet Android Yes
close Chrome Yes Edge 14 Firefox Yes IE No Opera Yes Safari Yes WebView Android No Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS No Samsung Internet Android Yes
data Chrome Yes Edge 16 Firefox Yes IE No Opera Yes Safari ? WebView Android No Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS No Samsung Internet Android Yes
dir Chrome Yes Edge 14 Firefox Yes IE No Opera Yes Safari Yes WebView Android No Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS No Samsung Internet Android Yes
icon Chrome 22
22
5
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 14 Firefox 22
22
4
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE No Opera 25 Safari No WebView Android No Chrome Android Yes Firefox Android 22
22
4
Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android Yes Safari iOS No Samsung Internet Android Yes
image Chrome 53 Edge 18 Firefox No IE No Opera 40 Safari ? WebView Android No Chrome Android 53 Firefox Android No Opera Android 41 Safari iOS No Samsung Internet Android 6.0
lang Chrome Yes Edge 14 Firefox Yes IE No Opera Yes Safari Yes WebView Android No Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS No Samsung Internet Android Yes
maxActions Chrome Yes Edge 18 Firefox No IE No Opera Yes Safari ? WebView Android No Chrome Android Yes Firefox Android No Opera Android Yes Safari iOS No Samsung Internet Android Yes
onclick Chrome Yes Edge 14 Firefox 22 IE No Opera Yes Safari Yes WebView Android No Chrome Android Yes Firefox Android No Opera Android Yes Safari iOS No Samsung Internet Android Yes
onclose Chrome Yes Edge 14 Firefox Yes IE No Opera Yes Safari Yes WebView Android No Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS No Samsung Internet Android Yes
onerror Chrome Yes Edge 14 Firefox No IE No Opera Yes Safari Yes WebView Android No Chrome Android Yes Firefox Android No Opera Android Yes Safari iOS No Samsung Internet Android Yes
onshow Chrome Yes Edge 14 Firefox Yes IE No Opera Yes Safari Yes WebView Android No Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS No Samsung Internet Android Yes
permission Chrome Yes Edge 14 Firefox Yes IE No Opera Yes Safari Yes WebView Android No Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS No Samsung Internet Android Yes
renotify Chrome 50 Edge 79 Firefox No IE No Opera 37 Safari No WebView Android No Chrome Android 50 Firefox Android No Opera Android 37 Safari iOS No Samsung Internet Android 5.0
requestPermission Chrome 46 Edge 14 Firefox 47
47
From Firefox 70 onwards, cannot be called from a cross-origin IFrame.
From Firefox 72 onwards, can only be called in response to a user gesture such as a click 事件。
IE No Opera 40 Safari Yes WebView Android No Chrome Android 46 Firefox Android Yes Opera Android 41 Safari iOS No Samsung Internet Android 5.0
requireInteraction Chrome Yes Edge 17 Firefox No IE No Opera Yes Safari ? WebView Android No Chrome Android Yes Firefox Android No Opera Android Yes Safari iOS No Samsung Internet Android Yes
Secure context required Chrome 62 Edge ≤79 Firefox 67 IE No Opera 49 Safari ? WebView Android No Chrome Android 62 Firefox Android 67 Opera Android 46 Safari iOS No Samsung Internet Android 8.0
silent Chrome 43 Edge 17 Firefox No IE No Opera 30 Safari No WebView Android No Chrome Android 43 Firefox Android No Opera Android 30 Safari iOS No Samsung Internet Android 4.0
tag Chrome Yes Edge 14 Firefox Yes IE No Opera Yes Safari Yes WebView Android No Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS No Samsung Internet Android Yes
timestamp Chrome Yes Edge 17 Firefox No IE No Opera Yes Safari ? WebView Android No Chrome Android Yes Firefox Android No Opera Android Yes Safari iOS No Samsung Internet Android Yes
title Chrome Yes Edge 14 Firefox No IE No Opera Yes Safari Yes WebView Android No Chrome Android Yes Firefox Android No Opera Android Yes Safari iOS No Samsung Internet Android Yes
vibrate Chrome No Edge No Firefox No IE No Opera No Safari ? WebView Android No Chrome Android 53
53
Does not work on Android O or later regardless of Chrome version.
Firefox Android No Opera Android 41
41
Does not work on Android O or later regardless of Chrome version.
Safari iOS No Samsung Internet Android 6.0
6.0
Does not work on Android O or later regardless of Chrome version.
Available in workers Chrome 45 Edge ≤18 Firefox 41 IE No Opera 32 Safari ? WebView Android No Chrome Android 45 Firefox Android 41 Opera Android 32 Safari iOS No Samsung Internet Android 5.0

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
见实现注意事项。
要求使用供应商前缀或不同名称。
要求使用供应商前缀或不同名称。

另请参阅