2
votes

I'm just started using desktop notification in browsers to notify users about new tasks and events of tasks. But it's iportant to notify every user about every event, and it's iportant to never notify double.

I checked this descktop notification question and many others, but didn't find any way to handle the notification close event.

I just looking for something like this:

var n = new Notification(title, {body: msg, icon: url});
n.onClose(function() {
    // do something...
});

Is there any way in pure JavaScript or jQuery to handle the event when user close the notify box?

1

1 Answers

0
votes

Alright, got it working using addEventListener instead of onClose:

let n = new Notification('title')
n.addEventListener('close', () => console.log('closed'))

I only took a quick looks at the mozilla docs and I'm a little confused for they say that there has been an onClose but it's been removed.

MDN