可以方便的通过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的事件: