参考代码如下:
document.getElementById('notifyButton').onclick
= function ()
{
//检查浏览器是否支持Notification
if (window.Notification){
if(Notification.Permission==='granted'){
//创建消息通知
var notification
= new Notification('Hello
Notification',{body:"I
hope that all the browser will support this\ function!"});
//展示消息通知
notification.show();
}else {
//若权限不够则获取浏览器的通知权限
document.getElementById('requestButton').onclick
= function (){
Notification.requestPermission();
};
};
}else alert('你的浏览器不支持此特性,请下载谷歌浏览器试用该功能');
};