简体   繁体   English

防止Firefox Web通知自动关闭

[英]Prevent Firefox Web Notifications from automatically Closing

I've got Web Notifications working in Firefox in combination with Server Sent DOM events. 我已经在Firefox中使用Web Notifications与Server Sent DOM事件相结合。 Unfortunately the notifications disappear after about two to three seconds. 不幸的是,通知在大约两到三秒后消失。 I prefer Chrome's method of leaving the message visible (with a maximum of three displayed at any given time) until the user clicks the notification. 我更喜欢Chrome的留言方式(在任何给定时间最多显示三个),直到用户点击通知为止。

Here is what I have... 这是我的......

window.onload = function(e)
{
 if ('EventSource' in window)
 {//Server Sent DOM Events
  var sse = new EventSource('../mail/sse/');

  if (Notification.permission && Notification.permission!='granted')
  {
   Notification.requestPermission(function(status) {if (Notification.permission!=status) {Notification.permission = status;}});
  }
  else if (window.webkitNotifications && window.webkitNotifications.checkPermission()!=0)
  {
   document.getElementsByTagName('body')[0].addEventListener('click',function() {window.webkitNotifications.requestPermission();},false);
  }

  es.onclick = function(sse)
  {
   //
  }

  //doesn't work
  es.onclose = function(es) {es.preventDefault();}

  es.onmessage = function(sse)
  {
   if ('Notification' in window)
   {
    if (window.webkitNotifications)
    {
     var n = webkitNotifications.createNotification('images/stuff.gif','New Email Message(s)',sse.data);
     n.show();
     n.onshow = function() {setTimeout(notification.close,15000);}
    }
    else
    {
     var n = new Notification('New Email Message(s)',{icon:'images/stuff.gif',body:sse.data});
    }
   }
  }
 }
}

It's a known bug in Firefox... 这是Firefox中的一个已知错误...

https://bugzilla.mozilla.org/show_bug.cgi?id=875114 https://bugzilla.mozilla.org/show_bug.cgi?id=875114

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM