Reputation: 594
I have a script that shows a notification (HTML5), but after some time I want this notification to hide.
Is this possible? How do I hide the notification?
My code to do a notification:
function notifyMe(data){
if (!("Notification" in window)) {
console.log("This browser does not support desktop notification");
}else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (permission === "granted"){
var notification = new Notification("FOTÓGENA", data);
setTimeout(function(){
#hide the notification
}, 3000)
}
});
}else
console.log('Por favor dale en permitir a las notificaciones')
}
Upvotes: 0
Views: 199
Reputation: 21769
Use the .close method of the notification api:
function notifyMe(data){
if (!("Notification" in window)) {
console.log("This browser does not support desktop notification");
}else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (permission === "granted"){
var notification = new Notification("FOTÓGENA", data);
setTimeout(function(){
notification.close()
}, 3000)
}
});
}else
console.log('Por favor dale en permitir a las notificaciones')
}
Upvotes: 1