Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!