javascript - 使用 jQuery JavaScript/任何插件推送通知
问题描述
使用 jQuery JavaScript/任何插件推送通知。
我有一项服务将返回如下数据:-
Error_Id、描述、日期时间等。
需要显示这些字段,它还应该包含两个按钮,即接受和拒绝。
点击接受/拒绝按钮应该调用另一个服务。
尝试了 jQuery 通知,但它不像浏览器通知 api 那样工作。当浏览器最小化时,它会全部最小化。
尝试了浏览器通知,但无法添加两个自定义按钮。
参考链接:- https://web-push-book.gauntface.com/chapter-05/02-display-a-notification/#title-and-body-options
还提到下面的链接,它清楚地提到不能添加按钮:- 带有 HTML 标记的桌面通知(代码示例)?
任何帮助将不胜感激。谢谢!
解决方案
使用链接在 Web 应用程序中添加推送通知。
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().then(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.
}