对于发送桌面通知,我使用此代码。(来自https://developer.mozilla.org/en/docs/Web/API/notification)
<button onclick="notifyMe()">Notify me!</button>
function notifyMe() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!");
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them any more.
}
当我按下按钮时,这将在同一页面上工作,但是如果我想动态管理这些通知该怎么办?即如果我从后端(管理员)推送通知,它应该向前端显示消息(允许通知的用户)