请知悉:本文最近一次更新为 9年 前,文中内容可能已经过时。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>弹出提示</title>
</head>
<body>
<script type="text/JavaScript">
function notifyMe() {
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}

else if (Notification.permission === "granted") {
var notification = new Notification("Hi there!");
}

// Otherwise, we need to ask the user for permission
// Note, Chrome does not implement the permission static property
// So we have to check for NOT 'denied' instead of 'default'
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {

// Whatever the user answers, we make sure we store the information
if(!('permission' in Notification)) {
Notification.permission = permission;
}

// If the user is okay, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}

// At last, if the user already denied any notification, and you
// want to be respectful there is no need to bother him any more.
}
</script>
<button onclick="notifyMe()">Notify me!</button>
</body>
</html>

整理自:https://url.cn/NGixjh
https://www.cnblogs.com/lxshanye/p/3560188.html

W3C标准的Notification

/**
* 显示notification,by Notification
* @return {[type]}
*/
var _showNotificationByW3C = function(){
window.indexForNotify = window.indexForNotify ++window.indexForNotify : 1;
var notify = new Notification(
"Alien: " + (new Date()).toUTCString(),
{
iconUrl : Session.staticDomain + "/img/alien20.jpg",
tag : 'tag_by_alien',
body : "你好,这个是通过Notification来创建的,这的名字叫:Demo"
+ window.indexForNotify + ","
+ "你可以通过它来做一些很炫的桌面提醒应用!这个API还很不成熟,"
+ "连个icon都显示不出来!!!它哭着对我说,API都是骗人的!"
});
notify.onerror = function(event){
console.log("error事件被触发:",event);
};
notify.onshow = function(event){
console.log("show事件被触发:",event);
};
notify.ondisplay = function(event){
console.log("display事件被触发:",event);
};
notify.onclick = function(event){
console.log("click事件被触发:",event);
notify.cancel();
};
notify.onclose = function(event){
console.log("close事件被触发:",event);
};
notify.show();
};

摘自: https://www.baidufe.com/item/3690af56196c85bf66a0.html


如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《Firefox-Chrome-html5弹出桌面通知》相关的博文:


留言

avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌