Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the close time of the HTML5 desktop notification to not autoclose?

I am working with the HTML5 desktop notification. it's working well and give me proper output as per my requirements. Now, I want to display that notification until user close that notification manually how it.s possible my code is as following.

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);
          }
        });
      }
    }
like image 934
Uday A. Navapara Avatar asked Dec 04 '14 10:12

Uday A. Navapara


People also ask

Which two of the following methods close an alert shown by web browser?

close() Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers. The close() method of the Notification interface is used to close/remove a previously displayed notification.

How do desktop notifications work?

Browser notifications are simply notifications that can be sent by web applications and websites. The messages are received by the user's browser client. Browser notifications can be sent even when the particular website is not actively in use.


2 Answers

It stays indefinitely on Chrome. There's a bug in Firefox which auto-closes it after 4 seconds: https://bugzilla.mozilla.org/show_bug.cgi?id=875114

like image 147
Riwen Avatar answered Sep 26 '22 03:09

Riwen


Try with "requireInteraction" in the option, will work in firefox and chrome both. The code is:

var options = {
                  body: "due to your inactive response timer is stoped automatically. Start your timer again.",
                  dir : "ltr",
                  requireInteraction: true
              };
like image 33
Robin Avatar answered Sep 23 '22 03:09

Robin