Notification in javascript / HTML 5

0

I've done javascript below to view notifications. It works and is called every 10 seconds. However, when two notification windows appear, only one is closed automatically. Is it possible for me to close it after a while or is it always the user who has to manually close it? Thank you.

    function notify(mensagem) {
        Notification.requestPermission(function() {
                var notification = new Notification("Vai aparecer notificação!", {

                icon: 'favicon.ico', 
                icon: 'logo.png',
                body: mensagem

            });
            notification.onclick = function() {

                window.open("http://www.site.com");

            }


        });
    } 
    
asked by anonymous 28.09.2018 / 19:51

1 answer

0

I managed to resolve. I used setTimeout. The corrected function is below, for those who need = D

function notify(mensagem) {
    Notification.requestPermission(function() {
    var notification = new Notification("Vai aparecer notificação!", {

        icon: 'favicon.ico', 
        icon: 'logo.png',
        body: mensagem


    });
    notification.onclick = function() {

        window.open("http://www.site.com");

    }
    // Fecha após 3 segundos
    setTimeout(notification.close.bind(notification), 3000);


   });
} 
    
28.09.2018 / 20:01