notification
只读特性在
NotificationEvent
interface returns the instance of the
Notification
that was clicked to fire the event. The
Notification
provides read-only access to many properties that were set at the instantiation time of the Notification such as
tag
and
data
attributes that allow you to store information for defered use in the
notificationclick
事件。
A
Notification
对象。
self.addEventListener('notificationclick', function(event) {
console.log('On notification click');
// Data can be attached to the notification so that you
// can process it in the notificationclick handler.
console.log('Notification Tag:', event.notification.tag);
console.log('Notification Data:', event.notification.data);
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 'notification' in that specification. |
实时标准 | Living standard. |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
见实现注意事项。
NotificationEvent
action
notification