2
我已經在Firefox中使用Web Notifications與Server Sent DOM事件結合使用。不幸的是,通知在大約兩到三秒後消失。我更喜歡Chrome瀏覽器的消息顯示方式(在任何給定時間最多顯示三個消息),直到用戶單擊通知。阻止Firefox Web通知自動關閉
這是我有...
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});
}
}
}
}
}
移動談話[如何更改桌面HTML5的關閉時間通知不autoclose?](https://stackoverflow.com/questions/27291297/how-to-change-the-close-time-of-the-html5-desktop-notification-to-not-autoclose) – rogerdpack