我正在创建浏览器通知,它在 Firefox 和 Edge 中运行良好。但由于某种原因,它在 Chrome 中不起作用。我可以看到通知,但当我单击通知时,它不会被触发。这是我的代码:
function notifyMe(text) {
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('Notification title', {
body: text,
requireInteraction: true
});
notification.onclick = function (event) {
alert("clicked");
event.preventDefault();
console.log('Notification clicked.');
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,为什么 notificaion.onclick 在 chrome 中不会被触发?