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

115
Visualizações
redirect user after click on notification with js

i'm using this code to push notification to my user:

Notification.requestPermission(function(result) {
                    if (result === 'granted') {
                        navigator.serviceWorker.ready
                            .then(function(registration) {
                                registration
                                    .showNotification('new message from ' + message.user, {
                                        body: message.message,
                                        vibrate: [200, 100, 200, 100, 200, 100, 200],
                                        tag: 'message'
                                    });
                            })
                        ;
                    }else {
                        alert('new message from ' + message.user + '\n please allow notification to get notification when a message receive.')
                    }
                });

how to redirect user to specific url after click on notification?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

i try this and work, hope useful for others.

Notification.requestPermission(function(result) {
                    if (result === 'granted') {
                        navigator.serviceWorker.register('/sw.js');
                        navigator.serviceWorker.ready
                            .then(function(registration) {
                                registration
                                    .showNotification('new message from ' + message.user, {
                                        body: message.message,
                                        vibrate: [200, 100, 200, 100, 200, 100, 200],
                                        tag: 'message',
                                        data : {email: message.email}
                                    })
                                ;
                            })
                        ;
                    }else {
                        alert('new message from ' + message.user + '\n please allow notification to get notification when a message receive.')
                    }
                });

and in 'sw.js' file add this :

self.addEventListener('notificationclick', function(event) {
    clients.openWindow('url');
    event.notification.close();
}, false);
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