2

Push notifications using jQuery JavaScript/any plugin.

I have a service that will return data as follows:- 

Error_Id, Description, DateTime, Etc.

Need to display these fields and it should also contain two buttons i.e. Accept & Reject.

On click of accept/reject button should call another service.

Tried jQuery notifications, but it does not work like browser notifications apis. When browser is minimized it will all minimize.

Tried browser notifications but could not add two custom buttons.

Ref link:- https://web-push-book.gauntface.com/chapter-05/02-display-a-notification/#title-and-body-options

Also referring the below link it clearly mentions cannot add buttons:- Desktop Notification with HTML Markup ( code example )?

Any help shall be greatly appreciated. Thanks!

Dev
  • 410
  • 5
  • 23

1 Answers1

4

Use Link for add push notification in web application.

function notifyMe() {
  // Let's check if the browser supports notifications
  if (!("Notification" in window)) {
    alert("This browser does not support desktop notification");
  }

  // Let's check whether notification permissions have already been granted
  else if (Notification.permission === "granted") {
    // If it's okay let's create a notification
    var notification = new Notification("Hi there!");
  }

  // Otherwise, we need to ask the user for permission
  else if (Notification.permission !== "denied") {
    Notification.requestPermission().then(function (permission) {
      // If the user accepts, let's create a notification
      if (permission === "granted") {
        var notification = new Notification("Hi there!");
      }
    });
  }

  // At last, if the user has denied notifications, and you 
  // want to be respectful there is no need to bother them any more.
}
Shivam Mishra
  • 319
  • 3
  • 15
  • Can you please tell me how can I add 2 or 3 buttons and handle the event for the same? – Dev Jan 10 '20 at 12:46
  • Don't need to add 2 or 3 button on document.ready run Notification.requestPermission().then(function (permission) { // If the user accepts, let's create a notification if (permission === "granted") { var notification = new Notification("welcome"); } }); and once user granted permission for notification Use var notification = new Notification("Hi there!"); for notification – Shivam Mishra Jan 13 '20 at 06:11
  • Thanks! The design is such that we need to display 2 buttons on the ui. Or may be 3 buttons infuture. Any help would be greatly appreciated. – Dev Jan 13 '20 at 06:17