Notification H5通知
function showNotify(){
let msgTitle = '标题'; // 消息标题
let msgDir = 'auto'; // 消息文本显示方向 auto→
let msgLang = 'zh-CN'; // 消息语言
let msgId = 'msgId'+Math.random(); //实例化的notification的id
let msgIcon = 'https://www.wangwm.cn/myFile/d5a2356a243e641116163bdfe261812_1591431666269.jpg'; //icon的值显示通知图片的URL 跨域无法显示 可相对路径
let msgContent = '内容'; // 消息文本内容
let Notification = window.Notification || window.mozNotification || window.webkitNotification;
if(Notification){
Notification.requestPermission(function(status){
if(status != "granted"){
return;
}else{
//msgObj
let msgObj = new Notification(msgTitle,{dir:msgDir,lang:msgLang,tag:msgId,icon:msgIcon,body:msgContent});
msgObj.onclick = function(event) {
event.preventDefault(); // 阻止默认动作 防止出现多个通知框
// 通知打开动作
alert(11)
};
msgObj.onerror = function () {
console.log("通知出错!!!");
};
msgObj.onshow = function () {
setTimeout(function(){
msgObj.close();
},5000)
};
msgObj.onclose = function () {
console.log("通知关闭!");
};
}
});
}else{
console.log("您的浏览器不支持通知!");
}
};