堆栈溢出桌面通知如何工作? [英] How do Stack Overflow desktop notifications work?
问题描述
在Stack Overflow聊天室中,有一个按钮启用桌面通知,它会显示一些内容系统托盘当有人回复你。
通过什么机制,这工作?这总让我好奇。
网站如何访问系统托盘?
它使用 Notification
对象(即 var n = new Notification(Hello);
)来提供本地通知每个网站的基础。每个浏览器都采用不同的标准(请参阅 Chrome , Firefox 和 Safari ),但它们都以基本相同的方式运行,根据它们拥有的权限(窗口)发送通知。 Notification.permission
),它可以是 default
(没有被问到,在这种情况下,你会 window.Notification .requestPermission();
),授予
或拒绝
。 Opera和Internet Explorer目前不支持桌面通知。
Perhaps this is a fairly big and ambiguous question:
In the Stack Overflow chatrooms, there is a button to "enable desktop notifications," which will show something in the system tray when someone replies to you.
By what mechanism does this work? It's always made me curious.
How does a website access the system tray?
It uses the Notification
object (i.e. var n = new Notification("Hello");
) to provide local notifications on a per-website basis. Each browser implements the standard differently (see Chrome, Firefox, and Safari), but they all operate essentially the same way, sending notifications based on the permissions they have (window.Notification.permission
), which can be default
(hasn't been asked, in which case you would window.Notification.requestPermission();
), granted
, or denied
. Opera and Internet Explorer do not support desktop notifications at this time.
这篇关于堆栈溢出桌面通知如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!