如何在 Firefox 中保持通知打开状态?

2023-12-28

我有一个聊天程序,我希望人们离开他们的办公桌。当他们回来时,我希望通知仍然显示在屏幕上。 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');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Firefox 中保持通知打开状态? 的相关文章

随机推荐