gpt4 book ai didi

javascript - 如果同时发送多个通知,Firefox 不会显示桌面通知

转载 作者:可可西里 更新时间:2023-11-01 02:12:50 24 4
gpt4 key购买 nike

我正在尝试为我的应用程序实现桌面通知。如果发送一个通知,它工作正常,但是当同时发送多个通知时,firefox 不显示任何通知。 Chrome 不存在此问题。

这是 Firefox 做不到的事情吗?我的印象是通知选项中标签的使用是用来堆叠通知的。

代码:

function isNewNotificationSupported() {
if (!window.Notification || !Notification.requestPermission) return false;
if (Notification.permission == "granted") throw new Error("");
try {
new Notification("");
} catch (e) {
if (e.name == "TypeError") return false;
}
return true;
}

function notifyMe(aa, bb, cc, dd) {
if (!("Notification" in window)) {
//alert("This browser does not support desktop notification");
} else if (Notification.permission === "granted") {
if (!document.hasFocus() || cc == 1) {
var options = {
body: bb,
icon: "",
dir: "ltr",
tag: dd
};
var notification = new Notification(aa, options);

notification.onshow = function() {
setTimeout(notification.close.bind(notification), 15000);
};
}
} else if (Notification.permission !== "denied") {
if (isNewNotificationSupported()) {
Notification.requestPermission(function(permission) {
if (!("permission" in Notification)) {
Notification.permission = permission;
}

if (permission === "granted") {
var options = {
body: bb,
icon: "",
dir: "ltr",
tag: dd
};
var notification = new Notification(aa, options);

notification.onshow = function() {
setTimeout(notification.close.bind(notification), 15000);
};
}
});
}
}
}

notifyMe("New notification1","newtest","1","test1");
notifyMe("New notification2","newtest2","1","test2");

我为它创建了一个 jsfiddle:

http://jsfiddle.net/1bm0wyvf/

更新:我想我现在通过将其中一个 notifyMe 更改为:

setTimeout(function() { notifyMe("Newnotification1","newtest","1","test1"); }, 200);

Firefox 现在可以正确堆叠它们。

最佳答案

我正在使用以下函数,它在 Firefox/Linux 上运行良好。

function notif(message){

if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (!('permission' in Notification)) {
Notification.permission = permission
}
if (permission === "granted") {
let notification = new Notification(message)
}
})
}
}
notif("Hello world!!")

enter image description here

关于javascript - 如果同时发送多个通知,Firefox 不会显示桌面通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30462087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com