可以复制下来直接保存为.html文件打开即可
<!DOCTYPE html>
<html>
<head>
<title>H5调用win10系统通知</title>
</head>
<body>
<script type="text/javascript">
// 先去判断浏览器是否支持唤醒
if (window.Notification) {
let popNotice = () => {
if (!Notification.permission === 'granted') return
const notification = new Notification('您有一个新提醒', {
body: '下班啦!快跑,赶紧跑!'
})
// 点击事件,点击后通知的跳转
notification.onclick = function () {
window.open('https://blog.fxnws.com')
notification.close()
}
}
/* 授权过通知 */
if (Notification.permission === 'granted') {
popNotice()
} else {
/* 未授权,先询问授权 */
Notification.requestPermission(function (permission) {
popNotice()
})
}
}
</script>
</body>
</html>
评论 (0)