4-20 1,423 views
废话少说,直接上代码
function notifyMe(notification_title, body) {
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
//notification_title,通知标题
var notification = new Notification(notification_title, {
//显示通知的图标
//icon: '',
//通知的内容
body: body,
});
notification.onclick = function () {
parent.focus();
window.focus(); //just in case, older browsers
this.close();
};
}
}
//test
notifyMe("您有新的消息","hello world!")
注意:测试网站必须是https的
开启网站通知,如果开启后收不到通知,再检查下windows系统通知是否允许chrome: