html - 多个选项卡上的 Webkit 通知

标签 html google-chrome webkit notifications html5-notifications

我正在为我的应用程序使用 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/

相关文章:

webkit - 在 Centos 5.8 上使用 WebKitGTK+?

html - robots.txt 修复的重复内容?

jQuery 内容 Controller 没有正确显示和隐藏内容

google-chrome - 应用程序或扩展程序可以在具有 "<all_urls>"权限的系统上打开文件吗?

google-chrome - 另一个 Chrome 问题!随机滚动?

xcode - 类型 "WKWebView"的值没有成员 "scrollView"

html - 将文本向上移动?

html - "Full screen"&lt;iframe&gt;

google-chrome - 使用chrome扩展程序获取所有窗口中所有标签的网址

google-chrome - 使用 CSS 转换后文本模糊 : scale(); in Chrome