3

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);
          }
        });
      }
    }
rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Uday A. Navapara
  • 1,237
  • 5
  • 20
  • 40
  • 1
    yes I am also finding solution for this. Somewhere I have got solution for this autoClose : 0 but this is not working if any one has solution then please give me as soon as possible. – Uday A. Navapara Dec 04 '14 at 10:16
  • Possible duplicate of [Prevent Firefox Web Notifications from automatically Closing](https://stackoverflow.com/questions/19144097/prevent-firefox-web-notifications-from-automatically-closing) – John Jan 05 '18 at 12:17
  • Duplicate of a higher quality *and* older post: https://stackoverflow.com/questions/19144097/prevent-firefox-web-notifications-from-automatically-closing – John Jan 05 '18 at 12:17

2 Answers2

4

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

Riwen
  • 4,734
  • 2
  • 19
  • 31
  • OK, I got it then now what is the solution for the Mozila display itme? and yes thanks for the solution. – Uday A. Navapara Dec 04 '14 at 11:03
  • There's a workaround, although it's a bit messy. Check this out: https://bugzilla.mozilla.org/show_bug.cgi?id=875114#c34 – Riwen Dec 04 '14 at 11:14
  • These days chrome on OS X automatically closes it after 4. Maybe you could bind to its onclose method and reshow it... – rogerdpack Jul 18 '17 at 14:31
1

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
              };
Robin
  • 11
  • 4