浏览器也可以调用Win10系统的消息提示,纯JS代码,复制到HTML网页中直接打开即可。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 判断浏览器是否支持唤醒
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();
});
}
}