【发布时间】:2018-01-31 16:48:44
【问题描述】:
我正在尝试显示通知并在单击它时执行某些操作。
try {
navigator.serviceWorker.getRegistration()
.then(reg => {
reg.showNotification("Guarda il videoclip!", {
body: "clicca qua!",
icon: "images/she_is_fire.png",
vibrate: [100, 50, 100],
tag: 'sample',
actions: [{ action: 'explore', title: 'Guarda', icon: 'images/she_is_fire.png' }],
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
window.open("https://youtu.be/PAvHeRGZ_lA");
}, false);
})
.catch(err => alert('Service Worker registration error: ' + err));
} catch (err) {
alert('Notification API error: ' + err);
}
我添加了事件监听器,但它从未被触发。
我做错了什么?
【问题讨论】:
标签: javascript notifications progressive-web-apps