浏览器也可以调用Win10系统的消息提示,纯JS代码,复制到HTML网页中直接打开即可。
代码
代码语言:javascript
复制// 判断浏览器是否支持唤醒
if (window.Notification) {
let popNotice = () => {
if (!Notification.permission === 'granted') return
const notification = new Notification('Hello', {
icon: require('@/assets/images/panel/logo.png'),
body: '欢迎访问韩小韩博客~~~'
})
notification.onclick = function () {
window.open('https://baidu.com')
notification.close()
}
}
/* 授权过通知 */
if (Notification.permission === 'granted') {
popNotice()
} else {
/* 未授权,先询问授权 */
Notification.requestPermission(function (permission) {
popNotice()
})
}
}