当网站选项卡关闭时,如何向 Chrome 发送通知?
How can I send notifications to Chrome when the website tab is closed?
我正在尝试了解如何在我的网站关闭时使用浏览器发送通知。
我看到 Facebook 做到了,但我不知道怎么做。
欢迎任何帮助。
您正在寻找 Push API:
The Push API gives web applications the ability to receive messages pushed to them from a server, whether or not the web app is in the foreground, or even currently loaded, on a user agent. This lets developers deliver asynchronous notifications and updates to users that opt in, resulting in better engagement with timely new content.
The Notification interface of the Notifications API is used to configure and display desktop notifications to the user.
您必须将它们与 Service Worker 结合使用。来自 Push API 文档:
For an app to receive push messages, it has to have an active service worker. When the service worker is active, it can subscribe to push notifications using PushManager.subscribe().
您可以使用 Roost。 Roost 是网站的推送通知平台。您可以查看其文档以执行客户端和服务器端集成,以便您可以根据需要自定义 Roost 通知。
我正在尝试了解如何在我的网站关闭时使用浏览器发送通知。
我看到 Facebook 做到了,但我不知道怎么做。
欢迎任何帮助。
您正在寻找 Push API:
The Push API gives web applications the ability to receive messages pushed to them from a server, whether or not the web app is in the foreground, or even currently loaded, on a user agent. This lets developers deliver asynchronous notifications and updates to users that opt in, resulting in better engagement with timely new content.
The Notification interface of the Notifications API is used to configure and display desktop notifications to the user.
您必须将它们与 Service Worker 结合使用。来自 Push API 文档:
For an app to receive push messages, it has to have an active service worker. When the service worker is active, it can subscribe to push notifications using PushManager.subscribe().
您可以使用 Roost。 Roost 是网站的推送通知平台。您可以查看其文档以执行客户端和服务器端集成,以便您可以根据需要自定义 Roost 通知。