ie-web-notifications / ie-web-notifications.github.io

IE Web Notifications (desktop notifications)
http://ie-web-notifications.github.io/
8 stars 2 forks source link

Notification is not hiding automatically #16

Closed ambujkhanna closed 8 years ago

ambujkhanna commented 8 years ago

Hi,

I am facing 2 issues: 1) Notification is not hiding automatically 2) If my window/browser is not in the background then still I am receiving notification.

Can you help me on these issues?

Thanks in advance!!!!

ie-web-notifications commented 8 years ago

Hi! Thanks for the report.

That's actually correct, the standard does not say that notifications should be automatically hidden or not shown when the tab is already active. It's the responsibility of notification initiator.

1) Notification is not hiding automatically

You can achieve it with several ways. E.g.:

var n = new Notification("It will be closed in 3 sec");
setTimeout(function(){this.close();}.bind(n), 3000);

However, there is an opportunity to miss the delivering of a notification to the user. Let's say the user has very active communication habit and receives a lot of notifications, the number of notifications shown at the same time can be limited according to current standard and it is indeed limited by 3 at least in current versions of Google Chrome and IE Web Notifications for better UX. To avoid it one could use onshow handler and close the notification only after it has been actually shown, albeit onshow handler is considered as deprecated now. The following code works only for IE Web Notifications

(new Notification("It will be closed in 3 sec")).onshown = function(){setTimeout(function(){this.close();}.bind(this), 3000);}

Important note: I'm sorry, there is a typo in the code for IE Web Notifications, it is called onshown not onshow (there is additional 'n' at the end). Please also pay attention that EventTarget is not currently implemented in IE Web Notifications.

2) If my window/browser is not in the background then still I am receiving notification

You can try to use Page Visibility API, in particular document.hidden, document.visibilityState and listen when the value of the attribute changed by document.addEventListener('visibilitychange', your-on-attribute-changed-handler). So when the document is active don't create notifications, however of course if the notification has been queued and the tab became inactive it will be shown.

ambujkhanna commented 8 years ago

Thanks. IE code is working but only issue i am facing is that if I am giving 5mins timeout in Chrome and Firefox then it's not taking but IE is taking. Firefox and chrome is taking max 15-20secs only.

ie-web-notifications commented 8 years ago

I can only recommend to double check the code, several minutes timeouts should work in both, in chrome and in firefox.

ambujkhanna commented 8 years ago

Thanks :)