Javascript/HTML5: Showing a notification popup message with the Notification API

You can show a small notification popup with the Notification API.

You first do Notification.requestPermission() to ask for permission.

Once you've got it, you can make a new Notification object. These have various options but we're just showing some text.

You can see the source below and a live example here:

  <button onclick="notify()">Notify me</button>


    function notify() {

      if (!("Notification" in window)) {
        alert("This browser does not support system notifications");
      } else {
        .then(function(result) {
          if (result === "granted") {
            new Notification("Hi there!");
          } else {
            console.log("permission was not granted.")


javascript html html-notification

Edit on github
comments powered by Disqus
Click me