如何在HTML页面中收听Javascritpt中的Notification?

时间:2017-08-24 05:49:11

标签: javascript reactjs push-notification

我有一个html文件,当此页面打开时,在某种情况下,会有一个桌面通知。我想听通知发生,并运行一些脚本。

npm install

我有什么办法找出<html> ... <script> var title = document.title if (notification happens) { window.onblur = function() { document.title = "You got a new msg"; }; } window.onfocus = function() { document.title = title; }; </script> ... </html>

1 个答案:

答案 0 :(得分:0)

你可以像正确的DOM元素一样监听.onclick,或者添加一个事件监听器:

notification.addEventListener('click', (e) => {
    //you can only access the event (e) in this case
});

或点击

notification.onclick = e => {
    //you can only access the event (e) in this case
}