Search code examples
javascripthtmlhtml5-notifications

Let HTML5 Notification disappear after a delay?


I want to use HTML5 notifications which work great.

The problem is that they never disappear.

How can I set a delay after which the HTML5 notification disappear?


Solution

  • You can just call the .close() method:

    var n = new Notification("Hello");
    setTimeout(n.close.bind(n), 2000);
    

    See here on MDN for details.