javascript - Web Notification API - 网站不需要打开?

标签 javascript html web-notifications

我注意到一些新闻站点(例如华盛顿邮报)能够弹出 Web 通知,即使我没有在选项卡中打开该站点。我不记得这在以前是可能的。如果网站未打开,网站怎么可能执行必要的 JS?如何使用 Web Notifications 实现这一点,是否有特定的设置来实现这一点?

最佳答案

我相信他们正在通过 Service Workers 使用推送通知.

您可以查看 current support status看看它是否适合你。它在现代浏览器中得到了很好的支持(尽管可能不是完整的规范)。

A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction. Today, they already include features like push notifications and background sync.

A service worker has a lifecycle that is completely separate from your web page.

关于javascript - Web Notification API - 网站不需要打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39859872/

相关文章:

javascript - inquirer.js - 将 BottomBar 与顺序日志相结合

javascript - 如何在不中断动画的情况下清除 Canvas ?

javascript - NodeJs : Filter mongo query results with results from another collection

html - IE 和 Chrome 特定问题 - Firefox 可以正常显示导航

html - 我对是否将图像用于文本或谷歌字体有些困惑

Html 类型值无效

html - 网络应用程序可以提供桌面通知吗

push-notification - notification.permission 设置为拒绝且不存在于阻止中

html - 有什么方法可以将推送式网络通知发送到移动设备?

javascript - 如何在事件处理程序中包含函数(及其参数),而无需在页面加载时调用该函数?