官方Web Api:https://developer.mozilla.org/zh-CN/docs/Web/API/notification/Notification
疑问:为何直接在前端html文件里面写,然后用谷歌浏览器打开html文件,然后就没反应。通过iis打开的页面就有反应。
if (window.Notification) {
if (Notification.permission == "granted") {
popNotice();
}else if( Notification.permission != "denied"){
Notification.requestPermission(function (permission) {
popNotice();
});
}
} else {
alert('浏览器不支持Notification');
}
var popNotice = function() {
if (Notification.permission == "granted") {
var notification = new Notification("Hi,", {
body: '可以加你为好友吗?'
//icon: '/static/cute.gif'
});
notification.onclick = function() {
alert('***已于' + new Date().toTimeString().split(' ')[0] + '加你为好友!');
notification.close();
};
}
notification.onshow = function(){
}
notification.onclose = function(){
}
notification.onerror = function(){
}
};