Web Push Notification-Message

by dr_eg   Last Updated July 11, 2019 19:04 PM

How to send a push notification message its time the user goes online but not necessarily opens a web browser? So far my code is, which allows the user to receive a push message its time he enters the site. Any suggestions?

$( document ).ready(function() {
    navigator.serviceWorker.register('service-worker.js');
    var titleElement = "summer";
    var messageElement = "bloom";
    function showNotification() {
      Notification.requestPermission(function(result) {
        if (result === 'granted') {
          navigator.serviceWorker.ready.then(function(registration) {
            registration.showNotification(titleElement, {
              body: messageElement,
              icon: 'images/android-icon-36x36.png',
              vibrate: [200, 100, 200, 100, 200, 100, 200],
              tag: 'vibration-sample'
            });
          });
        }
      });
    }
    setCookie('notify','2', 2);
    var x = getCookie('notify');

    if (x) {
        showNotification();
    }

}); 


Related Questions



Develop a Paid Subscription Web App

Updated March 14, 2016 08:01 AM

Duplicate CSS files in Firefox Inspector

Updated May 12, 2017 11:04 AM


Understand technology behind website

Updated May 14, 2019 22:04 PM