概述 桌面通知(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的事件: