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!

2
  • What you have tried, please show us the code which is not working Commented Jan 10, 2020 at 10:46
  • I've updated 2 links containing ref code and another stating cannot add buttons. Commented Jan 10, 2020 at 11:09

1 Answer 1

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.
}
Sign up to request clarification or add additional context in comments.

3 Comments

Can you please tell me how can I add 2 or 3 buttons and handle the event for the same?
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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.