我正在为我的应用程序使用 WebKit 通知。假设我正在使用这段代码:
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: 前五行实际上是一行。为了便于阅读,我以这种方式发布。
PS 2:完整代码请看:Unable to show Desktop Notifications using Google Chrome .
我的问题是,如果我打开了多个标签怎么办?
说当我的应用程序上出现新评论时它是否会被触发。如果我打开了多个标签怎么办?这会产生很多通知吗?比如说,我打开了 10 - 15
标签,我收到了两个通知。将生成多少条通知,20 - 30
?
如果是这样,如何防止为每个打开的选项卡多次生成单个通知?
最佳答案
您只需要为通知指定“标签”选项。即使打开多个标签,标签中具有相同值的通知也只会显示一次。
例如:
var notification = new Notification('Hey!', {
body : 'So nice to hear from you',
tag : 'greeting-notify',
icon : 'https://mysite.com/my_funny_icon.png'
});
关于html - 多个选项卡上的 Webkit 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12928242/