Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webkit Notifications on Multiple Tabs

I am using WebKit Notifications for my app. Say if I am using this code:

var n = window.webkitNotifications.createNotification(
   'icon.png',
   'New Comment',
   'Praveen commented on your post!'
);
n.onclick = function(x) { window.focus(); this.cancel(); };
n.show();

PS 1: The first five lines are actually a single line. Just for readability I have posted this way.

PS 2: For the full code, please see this: Unable to show Desktop Notifications using Google Chrome.

My question is, what if I have more than one tab opened?

Say if this is gonna get fired when a new comment appears on my app. What if I have more than one tab open? Will this generate many notifications? Say, I have 10 - 15 tabs open and I get two notifications fired. How many notifications will be generated, 20 - 30?

If that is the case, how to prevent generation of a single notification multiple times for each opened tab?

like image 608
Praveen Kumar Purushothaman Avatar asked Oct 17 '12 06:10

Praveen Kumar Purushothaman


1 Answers

You just need to specify "tag" option for notification. Notifications with the same value in tag only shows once even if many tabs are opened.

For example:

var notification = new Notification('Hey!', {
    body : 'So nice to hear from you',
    tag : 'greeting-notify',
    icon : 'https://mysite.com/my_funny_icon.png'
});
like image 162
Alexander Vorobyov Avatar answered Oct 04 '22 11:10

Alexander Vorobyov