JS唤起Win10消息通知

EN
EN
2022-01-09 / 0 评论 / 347 阅读 / 正在检测是否收录...
// 判断浏览器是否支持唤醒
if (window.Notification) {
    let popNotice = () => {
        if (!Notification.permission === 'granted') return
        const notification = new Notification('阿巴阿巴', {
            body: '提示提示提示'
        })
        // 点击通知的回调函数
        notification.onclick = function () {
            window.open('https://baidu.com')
            notification.close()
        }
    }
      /* 授权过通知 */
    if (Notification.permission === 'granted') {
        popNotice()
    } else {
        /* 未授权,先询问授权 */
        Notification.requestPermission(function (permission) {
            popNotice()
        })
    }
}
0

评论 (0)

取消