使用 jQuery JavaScript/任何插件推送通知。
我有一项服务将返回数据,如下所示:-
Error_Id、描述、日期时间等
需要显示这些字段,并且还应该包含两个按钮,即接受和拒绝。
单击接受/拒绝按钮应调用另一个服务。
尝试过 jQuery 通知,但它不像浏览器通知 API 那样工作。当浏览器最小化时,它将全部最小化。
尝试过浏览器通知,但无法添加两个自定义按钮。
引用链接:- https://web-push-book.gauntface.com/chapter-05/02-display-a-notification/#title-and-body-options
另请参阅以下链接,它明确提到无法添加按钮:- Desktop Notification with HTML Markup ( code example )?
任何帮助将不胜感激。谢谢!
最佳答案
使用Link用于在 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.
}
关于javascript - 使用 jQuery JavaScript/任何插件推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59680069/