2014-12-04 19 views
5

我正在使用HTML5桌面通知。它運行良好,根據我的要求給我適當的輸出。現在,我想要顯示該通知,直到用戶手動關閉該通知爲止,可能我的代碼如下所示。如何將HTML5桌面通知的關閉時間更改爲不自動關閉?

function notifyMe() { 
     if (!("Notification" in window)) { 
     alert("This browser does not support desktop notification"); 
     } 
     else if (Notification.permission === "granted") { 
      var options = { 
        body: "due to your inactive response timer is stoped automatically. Start your timer again.", 
        dir : "ltr" 
       }; 
       var notification = new Notification("Your timer is stop",options); 

     } 
     else if (Notification.permission !== 'denied') { 
     Notification.requestPermission(function (permission) { 
      if (!('permission' in Notification)) { 
      Notification.permission = permission; 
      } 

      if (permission === "granted") { 
      var options = { 
        body: "due to your inactive response timer is stoped automatically. Start your timer again.", 
        dir : "ltr" 
       }; 
      var notification = new Notification("Your timer is stop",options); 
      } 
     }); 
     } 
    } 
+1

是我也在爲此尋找解決方案。某處我已經爲此解決方案 autoClose:0 但如果任何人有解決方案,這是行不通的,那麼請儘快給我。 – 2014-12-04 10:16:24

+0

[防止Firefox Web通知自動關閉]的可能重複(https://stackoverflow.com/questions/19144097/prevent-firefox-web-notifications-from-automatically-closing) – John 2018-01-05 12:17:28

+0

重複*更高質量*和*更舊發佈:https://stackoverflow.com/questions/19144097/prevent-firefox-web-notifications-from-automatically-closing – John 2018-01-05 12:17:56

回答

4

它無限期停留在Chrome上。在Firefox中有一個錯誤會在4秒後自動關閉它:https://bugzilla.mozilla.org/show_bug.cgi?id=875114

+0

好的,我明白了,那麼現在Mozila顯示器itme的解決方案是什麼?是的,謝謝你的解決方案。 – 2014-12-04 11:03:51

+0

有一個解決方法,雖然它有點混亂。檢查了這一點:https://bugzilla.mozilla.org/show_bug.cgi?id = 875114#c34 – Riwen 2014-12-04 11:14:29

+0

這些天在OS X上的鉻自動關閉它之後4.也許你可以綁定到它的onclose方法,並重新顯示它... – rogerdpack 2017-07-18 14:31:56

0

嘗試在選項中使用「requireInteraction」,它將在firefox和chrome中起作用。 代碼是:

var options = { 
        body: "due to your inactive response timer is stoped automatically. Start your timer again.", 
        dir : "ltr", 
        requireInteraction: true 
       };