Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda