gpt4 book ai didi

javascript - 如何在 Firefox 中保持通知打开?

转载 作者:行者123 更新时间:2023-11-29 19:35:45 24 4
gpt4 key购买 nike

我有一个聊天程序,我希望人们离开他们的办公 table 。当他们回来时,我希望通知仍然显示在屏幕上。 Chrome 可以永远保留通知,但 firefox 会自动关闭。这不是很好,因为用户不会盯着他们的显示器看

Firefox 似乎自动关闭通知。有什么好的方法可以让它保持打开状态吗?

最佳答案

我目前只是在通知关闭时重新打开它,当我明确关闭它(通过单击)时,我允许它实际关闭。

// This assumes you already checked for permissions and have notifications working

var MyNotify = function(message) {
this.message = message;
this.open();
};

MyNotify.prototype.open = function() {
var self = this;

// Notification is the native browser method
self.instance = new Notification(self.message);

self.instance.addEventListener('close', function(){
// We force firefox to continually respawn notifications until they explicitly close
if (!self.shouldClose)
self.open();
});

self.instance.addEventListener('click', function(){
self.close();
});

};

MyNotify.prototype.close = function() {
self.shouldClose = true;
self.instance.close();
};

new MyNotify('Hello World');

关于javascript - 如何在 Firefox 中保持通知打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25209805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com