I show a 'sticky' notification like this:
function show(text) {
let alreadyOn = false; // ??? how to get this ???
if (!alreadyOn) {
new Notification(text, {
requireInteraction : true
});
}
}
Notification.requestPermission();
show("first");
setTimeout(() => show("second"), 1000);
(note this just a sample and you need to permit notification the first time it runs and try again)
Is there a way for my code to later determine if this notification is still on or the user already dismissed it ? That is how to determine alreadyOn above ?
You can add an event handler with Notification.onclose method to do something when the Notification is closed by the user.
Notification.onclose = function () {
// do something...
}