The parameter passed into the
onnotificationclick
handler, the
NotificationEvent
interface represents a notification click event that is dispatched on the
ServiceWorkerGlobalScope
的
ServiceWorker
.
This interface inherits from the
ExtendableEvent
接口。
NotificationEvent()
NotificationEvent
对象。
Inherits properties from its ancestor,
事件
.
NotificationEvent.notification
只读
Notification
object representing the notification that was clicked to fire the event.
NotificationEvent.action
只读
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.
继承方法来自其父级
ExtendableEvent
.
ExtendableEvent.waitUntil()
Extends the lifetime of the event. Tells the browser that work is ongoing.
self.addEventListener('notificationclick', function(event) {
console.log('On notification click: ', event.notification.tag);
event.notification.close();
// This looks to see if the current is already open and
// focuses if it is
event.waitUntil(clients.matchAll({
type: "window"
}).then(function(clientList) {
for (var i = 0; i < clientList.length; i++) {
var client = clientList[i];
if (client.url == '/' && 'focus' in client)
return client.focus();
}
if (clients.openWindow)
return clients.openWindow('/');
}));
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
Notifications API
The definition of 'NotificationEvent' in that specification. |
实时标准 | Living standard. |
注意
: This interface is specified in the
Notifications API
, but accessed through
ServiceWorkerGlobalScope
.
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
NotificationEvent
|
Chrome 42 | Edge ≤18 |
Firefox
44
注意事项
|
IE ? | Opera 37 | Safari ? | WebView Android 不支持 No | Chrome Android 42 | Firefox Android 44 | Opera Android 37 | Safari iOS ? | Samsung Internet Android 4.0 |
NotificationEvent()
构造函数
|
Chrome 42 | Edge ≤18 |
Firefox
44
注意事项
|
IE ? | Opera 37 | Safari ? | WebView Android 不支持 No | Chrome Android 42 | Firefox Android 44 | Opera Android 37 | Safari iOS ? | Samsung Internet Android 4.0 |
action
|
Chrome 48 | Edge ≤18 |
Firefox
44
注意事项
|
IE ? | Opera 不支持 No | Safari ? | WebView Android 不支持 No | Chrome Android 48 | Firefox Android 44 | Opera Android 不支持 No | Safari iOS ? | Samsung Internet Android 5.0 |
notification
|
Chrome 42 | Edge ≤18 |
Firefox
44
注意事项
|
IE ? | Opera 37 | Safari ? | WebView Android 不支持 No | Chrome Android 42 | Firefox Android 44 | Opera Android 37 | Safari iOS ? | Samsung Internet Android 4.0 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
见实现注意事项。