Javascript: 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: https://repl.it/@newfivefour/notification-api?language=html&folderId=

  <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 notification

Edit on Github!

comments powered by Disqus