我注意到一些新闻站点(例如华盛顿邮报)能够弹出 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/