我想多次连续显示消息,为此我使用Notifications API,当我在chrome浏览器中运行代码时,一切都很好,但是当我在firefox中运行代码时,当我使用一个通知构造函数时,一切都很好,并且带有多个通知,什么也没有显示!
在代码中:
var options= {
body: 'test1'
};
new window.Notification('subj', options);
这在chrome和firefox中很好,但是:
var options= {
body: 'test1'
};
new window.Notification('subj', options);
new window.Notification('subj', options);
new window.Notification('subj', options);
在Chrome中显示三个消息,在Firefox中显示三个消息。
为什么firefox无法显示所有通知(例如chrome)?
还有其他方法可以在所有浏览器中完美显示客户端桌面上的通知吗?
最佳答案
我的临时解决方案不是很好,但是可以工作:
new Notification('a');
setTimeout(function() {
new Notification('b');
}, 200);
在我的Firefox中,使用30毫秒的超时效果很好,而使用20毫秒则没有任何反应。所以我现在用200ms留一点缓冲,因为我不知道其他浏览器的表现如何...