I am currently using this implementation to use browser-based notifications:
https://developer.mozilla.org/en-US/docs/Web/API/Notification
It works like a charm.
if ("Notification" in window) {
if(Notification.permission === "granted") {
if($('#notify-on-message').is(':checked')) {
var notification = new Notification(username + ' : ' + data, {'icon': "/custom/favicon.gif"});
}
if ($('#notify-on-hl').is(':checked')) {
var patt = new RegExp("(^|\\W)"+selfusername+"(\\W|$)");
if(patt.test(data)) {
var notification = new Notification(username + ' highlighted you.', {'icon': "/custom/favicon.gif"});
}
}
}
}
The main problem I'm experiencing is that in Chrome-based browsers, the notification simply does not close after a 3 second delay.
He tried to add this aftervar notification = ...
setTimeout(function() {
notification.close();
}, 2000);
Although this does not change anything. The notice remains.
Is this a known issue? Is there an easy way to fix this behavior that I don't want?
EDIT 1: According to this page:
https://developer.mozilla.org/en-US/docs/WebAPI/Using_Web_Notifications
This is a known issue:
. Firefox Safari , . 4 .
-, Notification.close(), , :
var n = new Notification("Hi!");
n.onshow = function () {
setTimeout(n.close, 5000);
}
. , , close - .