Reputation: 6267
I have a chat program and I expect people to leave their desk. When they come back, I would like notifications to still be on the screen. Chrome can leave up notifications forever, but firefox auto closes. This isn't great because users aren't going to be staring at their monitors
Firefox seems to auto close notifications. Is there a nice way to keep it open?
Upvotes: 2
Views: 523
Reputation: 6267
I am currently just re-opening the notification when it closes, and when I explicitly close it(with a click), then I allow it to be actually closed.
// This assumes you already checked for permissions and have notifications working
var MyNotify = function(message) {
this.message = message;
this.open();
};
MyNotify.prototype.open = function() {
var self = this;
// Notification is the native browser method
self.instance = new Notification(self.message);
self.instance.addEventListener('close', function(){
// We force firefox to continually respawn notifications until they explicitly close
if (!self.shouldClose)
self.open();
});
self.instance.addEventListener('click', function(){
self.close();
});
};
MyNotify.prototype.close = function() {
self.shouldClose = true;
self.instance.close();
};
new MyNotify('Hello World');
Upvotes: 3