【问题标题】:Push notifications using jQuery JavaScript/any plugin使用 jQuery JavaScript/任何插件推送通知
【发布时间】:2020-01-10 10:42:49
【问题描述】:

使用 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 )?

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

【问题讨论】:

  • 你试过的,请告诉我们不工作的代码
  • 我更新了 2 个包含参考代码的链接,另一个声明无法添加按钮。

标签: javascript jquery push-notification


【解决方案1】:

使用Link 在网络应用程序中添加推送通知。

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

【讨论】:

  • 你能告诉我如何添加 2 或 3 个按钮并处理相同的事件吗?
  • 不需要在document.ready上添加2或3按钮。运行Notification.requestPermission().then(function (permission) { //如果用户接受,让我们创建一个通知 if (permission === "授予") { var notification = new Notification("welcome"); } });并且一旦用户授予通知权限使用 var notification = new Notification("Hi there!");通知
  • 谢谢!设计是这样的,我们需要在 ui 上显示 2 个按钮。或者将来可能是 3 个按钮。任何帮助将不胜感激。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多