如何在Chrome中仅显示一个通知

时间:2016-03-14 08:16:17

标签: google-chrome google-chrome-extension notifications push-notification

我创建了Chrome扩展程序并使用pusher从服务器接收一些数据。 当我测试它显示多个重复数据,因为它遵循我打开的选项卡。 任何人都了解我。请帮助我。提前谢谢你。

Content.js

Pusher.Util.getLocalStorage = function() 
{ 
 return undefined; 
}
Pusher.ScriptRequest.prototype.send = function(receiver) {
 var xhr = new XMLHttpRequest();
 xhr.open("GET", this.src, true);
 xhr.send();
}
document.addEventListener('DOMContentLoaded', function () {
          if (Notification.permission !== "granted")
            Notification.requestPermission();
        });
        var pusher = new Pusher('xxxxxxxxxxxxxxxxxxxxx');
        var notificationsChannel = pusher.subscribe('notifications');
        notificationsChannel.bind('new_notification', function(notification){
            // assign the notification's message to a <div></div>
            var message = notification.message;
            if (!Notification) {
                alert('Desktop notifications not available in your browser. Try Chromium.'); 
                return;
              }
            if (Notification.permission !== "granted")
                Notification.requestPermission();
            else {
                console.log(message);
                var notification = new Notification('แจ้งเตือน', {
                  icon: 'img/LOGO.png',
                  body: message,
                });
                notification.onclick = function () {
                  location.reload();      
                };

              }
        }); 

duplicate notification

0 个答案:

没有答案