This is my code to show notification in Google Chrome.
How can I close notification in code?
document.addEventList
It's simple, every notification object has close()
method you need to just push them on to an array and call close()
on each one of them before window close
var notify=[];
for(var i=0; i<=4;i++){
var notification = new Notification('test', {
icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
body: "test"+i
}); //create some notifications
notify.push(notification);
}
function removeAllNotifys()
{
for(var i=0; i<notify.length;i++){
notify[i].close(); //remove them all
}
}
window.onbeforeunload = removeAllNotifys;
You can also associate removeAllNotifys()
on some button click to clear all notification or use setTimeout to remove them say after 2 seconds .