Web 通知 API - 网站不需要打开?
Web Notification API - website doesn't need to be open?
我注意到华盛顿 Post 等一些新闻网站能够弹出 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.
我注意到华盛顿 Post 等一些新闻网站能够弹出 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.