阻止Firefox Web通知自动关闭 [英] Prevent Firefox Web Notifications from automatically Closing

查看:154
本文介绍了阻止Firefox Web通知自动关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将Firefox中的Web Notifications与Server Sent DOM事件结合使用.不幸的是,通知会在大约两到三秒钟后消失.我更喜欢Chrome浏览器在用户单击通知之前保持可见(在任何给定时间最多显示三则)消息的方法.

I've got Web Notifications working in Firefox in combination with Server Sent DOM events. 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.

这就是我所拥有的...

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});
    }
   }
  }
 }
}

推荐答案

这是Firefox中的已知错误...

It's a known bug in Firefox...

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

这篇关于阻止Firefox Web通知自动关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆