Event Listener for Web Notification

后端 未结 2 1851
感动是毒
感动是毒 2021-01-07 08:15

Is there a way to set an event listener for a desktop notification?

document.addEventListener(\"desktop notification\", function(){
    // do something
});
         


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-07 09:07

    @marekful is right. Instead of placing global event listeners, you may consider placing a callback or even attach an event on the Notification object.

    var noticeMe = new Notification(title, options); 
    noticeMe.onshow = function() { console.log("easy!") };
    

    A full list of supported events may be found here: https://developer.mozilla.org/en-US/docs/Web/API/Notification, Also here is an article I wrote a few months back about the Notification API

    Take a look at

    • Notification.onclick

      Notification.onclose

      Notification.onerror

      Notification.onshow

提交回复
热议问题