Desktop notifications - Javascript

3

I need to send desktop notifications to the user, even when they are not open, but I can only call event notification (click, load, change ...). How could I send these notifications?

Notification.requestPermission(function() {
                var notification = new Notification("Casa de Cambio Santos", {
                    icon: 'http://teste.png',
                    body: "Texto texto texto texto"
                });
                notification.onclick = function() {
                    window.open("http://teste.com.br");
                }
            });
    
asked by anonymous 11.08.2017 / 22:49

1 answer

2

Based on the description you've been through you'll need to use Push API instead of so only Notifications API . Think of% s as Push as a Notifications with steroids.

Regardless of whether your site is static or dynamic, this API is API and runs on the user's browser, however it's a little harder to implement than Notificatios .

This javascript is available at Service Worker and needs a back-end as a service to actually send notifications to the client (user).

There is a great offer of services (servers) that do this back-end work for Push , which may even have good documentation for you to implement a Service Worker on your site, however if you have a server (manages) it can be a good idea to implement its own service and maintain full control over the notification system.

I usually do not like to post responses like: "follow this link here" bad, if you were to post the codes to implement Push with due clarification would be a very long in addition to "reinventing the wheel" with such a wide range of good materials and good sources.

Then follow the links:

The example of the site Google Developers is very good but does not teach you to create your own service if you are interested in diving head first you can start by taking a look at the list of libs hosted on GitHub I particularly recommend web-push made to run on Node.

editing:

A Cookie Book on Push API (perhaps the best I've ever read)

    
12.08.2017 / 04:55