簡體   English   中英

通知API:用戶不在現場時?

[英]Notification API: When user is off site?

用戶關閉應用程序/站點時是否可以發送瀏覽器通知?

if(window.Notification && Notification.permission !== "denied") {
Notification.requestPermission(function(status) {  // status is "granted", if accepted by user
    var n = new Notification('Title', { 
        body: 'I am the body text!',
        icon: '/path/to/icon.png' // optional
    }); 
});
}

只要標簽或頁面處於打開狀態,用戶都應收到通知。 您嘗試了什么,哪些沒有完全起作用?

當用戶關閉頁面時,無法再發送通知

從Chrome版本42開始,開發人員可以使用Push API和Notification API。 它利用服務人員來執行此操作。 服務工作者是由您的瀏覽器在后台運行的腳本,與網頁分開,為不需要網頁或用戶交互的功能打開了大門。

有關詳細信息,我建議您檢查以下內容:

在Google Chrome瀏覽器上推送通知: https : //developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web?hl=zh-CN

服務人員教程:
http://www.html5rocks.com/zh-CN/tutorials/service-worker/introduction/

有關如何使用服務人員進行推送通知的詳細教程: https : //gauntface.com/blog/2014/12/15/push-notifications-service-worker

這也適用於移動設備。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM