javascript - 使用 jQuery JavaScript/任何插件推送通知

标签 javascript jquery push-notification

使用 jQuery JavaScript/任何插件推送通知。

我有一项服务将返回数据,如下所示:- 

Error_Id、描述、日期时间等

需要显示这些字段,并且还应该包含两个按钮,即接受和拒绝。

单击接受/拒绝按钮应调用另一个服务。

尝试过 jQuery 通知,但它不像浏览器通知 API 那样工作。当浏览器最小化时,它将全部最小化。

尝试过浏览器通知,但无法添加两个自定义按钮。

引用链接:- https://web-push-book.gauntface.com/chapter-05/02-display-a-notification/#title-and-body-options

另请参阅以下链接,它明确提到无法添加按钮:- Desktop Notification with HTML Markup ( code example )?

任何帮助将不胜感激。谢谢!

最佳答案

使用Link用于在 Web 应用程序中添加推送通知。

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.
}

关于javascript - 使用 jQuery JavaScript/任何插件推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59680069/

相关文章:

jquery - 观察 DOM 变化,优雅的方式

javascript - 面向对象的 Javascript 与纯 jQuery 和 .data 存储

ssl - 从 coldfusion 发送推送通知?

php - 使用 PHP 向钛(跨平台)开发的 android 应用程序发送推送通知

android - GCM 通知 setAutoCancel(true) 在 Android 5.1.1 中不起作用

jquery - Bootstrap 选择加载在 IE 中花费的时间太长

javascript - 在jVectorMap中,如何仅在满足条件时选择区域?

javascript - 获取字符串中最后一个换行符的最有效方法是什么

javascript - 如何迭代 JSON 以创建表的主体 - jQuery tmpl/template

javascript - Jquery event.preventDefault