点击关闭Chrome通知

时间:2017-12-12 21:33:53

标签: javascript google-chrome push-notification web-push web-notifications

我正在尝试通过Chrome创建网络通知 我收到了通知,工作正常 问题是,当我点击通知时,它并没有消失 请点击/打开时帮我关闭通知

我目前有

let dnperm = document.getElementById("dnperm");
let dntrigger = document.getElementById("dntrigger");

dnperm.addEventListener("click", function(e) {
  e.preventDefault();

  if(!window.Notification) {
    alert("Sorry, Notifications are not supported!");
  } else {
    Notification.requestPermission(function(p) {
      if (p === "denied") {
        alert("You Denied");
      } else if (p === "granted") {
        alert("You Allowed");
      }
    });
  }
});

dntrigger.addEventListener("click", function(e) {
  let notify;
  e.preventDefault();
  if (Notification.permission ==="default") {
    alert("Allow Notifications First!");
  } else {
    notify = new Notification("New Message!", {
                     	"body": "Hello",
                     	"icon": "favicon.png",
                     	"tag": "123456",
                     	"image": "img/legendary.jpg",
    });

    notify.onclick = function() {
      window.location = "https://www.google.com/";
    };
  }
});
<a href="#" id="dnperm">Notifications</a>
<a href="#" id="dntrigger">Trigger</a>

1 个答案:

答案 0 :(得分:0)

您可以使用Notification.close()执行此操作。

notify.close()上,只需运行notify.onclick = function() { window.location = "https://www.google.com/"; notify.close(); };

public void RefreshDGV()
 {
     dataGridView1.DataSource = SQLHelper.otdc.StandartProds
          .Join(SQLHelper.otdc.Orders, a1 => a1.OrderID, a2 => a2.OrderID, (a3, a4) => new { a3, a4 })
          .Join(SQLHelper.otdc.Colors, b1 => b1.a3.ColorID, b2 => b2.ColorID, (b3, b4) => new { b3, b4 })
          .Select(x => x);
}