Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
set timeout to notification javascript

I have a website notification When sending the notification, it is sent now. I want to send it two hours after pressing the send notification button

CODE

 <button onclick="bell();">send</button>
function bell() {
  function notifyMe() {
    if (!("Notification" in window)) {
      alert("This browser does not support system notifications");
    }
    else if (Notification.permission === "granted") {
      notify();
    }
    else if (Notification.permission !== 'denied') {
      Notification.requestPermission(function (permission) {
        if (permission === "granted") {
          notify();
        }
      });
    }
    
    function notify() {
      var notification = new Notification('success now', {
        icon: 'blue.svg',
      });
  

      setTimeout(notification.close.bind(notification), 3000); 
      var notification = new Notification('success 2 hours', {
        icon: 'blue.svg',
      });      notification.onclick = function () {
        window.open("INDEX.HTML");      
      };
    }
  
  }
  notifyMe();
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use this code:

<!DOCTYPE html>
<html>
<body>
    <button onclick="bell()">Show notification</button>
    <script type="text/javascript">
        const granted = (async () => {
            let granted = false;
            if (Notification.permission === 'granted') {
                granted = true;
            } else if (Notification.permission !== 'denied') {
                let permission = await Notification.requestPermission();
                granted = permission === 'granted' ? true : false;
            }
            return granted;
        })();
        const showNotification = (msg) => {
            const notification = new Notification('success', {
                body: msg,
                icon: 'blue.svg'
            });
            setTimeout(() => {
                notification.close();
            }, 3 * 1000);

            notification.onclick = () => {
                window.focus();
            }
        }
        function bell() {
            granted && showNotification("Hello World"); // short for if (granted) showNotification(...)
        }
    </script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda