<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试页面</title>
</head>
<body>
<button onclick="onNotice('承兑库','HelloWord')">这是一个按钮</button>
</body>
<script>
function onNotice(title,body) {
if (!("Notification" in window)) {
alert("不支持 notification");
} else if (Notification.permission === "granted") { // 允许通知
notice(title,body)
}else if (Notification.permission !== 'denied') { // 用户没有选择是否显示通知,向用户请求许可
Notification.requestPermission(function(permission) {
if (permission === "granted") {
notice(title,body)
}
});
}
}
function notice(title,body) {
var notification = new Notification(title,{
body:body,
icon:"https://mp.weixin.qq.com/misc/getheadimg?token=990524500&fakeid=3006291623&r=674680"
});
notification.onclick = function(){
window.open("http://120.79.14.150:8080/");
};
setTimeout(function () {
notification.close();
},3000);
}
</script>
</html>