目录

桌面通知

 

概述

可以方便的通过Notifications API为web应用添加桌面通知功能。

示例

if(window.Notification) {
  if(window.Notification.permission !== "granted") {
    Notification.requestPermission();
  }
  notify();
} else {
  console.log("当前浏览器不支持桌面通知!");
}
function notify() {
  var notification = new window.Notification("this is notification title", {
    icon: "",
    body: "hey there! this is notification body!"
  });
  notification.onclick = function() {
    // do something
  }
}

效果

代码说明

Notification的三个参数:

Notification的事件: