Reputation: 329
I am trying to implement desktop notifications for my application. It works fine if one notification is sent, however when more than one is sent at the same time, firefox does not display any of them. This problem is not present with Chrome.
Is this something that is just not possible with firefox? I was under the impression that the usage of tags inside the notification options were used for stacking notifications.
Code:
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");
I created a jsfiddle for it at:
Update: I think i solved it now by changing one of the notifyMe's to:
setTimeout(function() { notifyMe("Newnotification1","newtest","1","test1"); }, 200);
Firefox properly stacks them now.
Upvotes: 13
Views: 1873
Reputation: 13077
I am using the following function and it behave very well on 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!!")
Upvotes: 1