Desktop Notification Using JavaScript

function notifyMe(title, options) {
  // Check if the browser supports notifications
  if (!("Notification" in window)) {
    console.log("This browser does not support desktop notification");
  }

  // Check whether notification permissions have alredy been granted
  else if (Notification.permission === "granted") {
    // If it's okay let's create a notification
    var notification = new Notification(title, options);
  }

  // Otherwise, we need to ask the user for permission
  else if (Notification.permission !== 'denied') {
    Notification.requestPermission(function (permission) {
      // If the user accepts, let's create a notification
      if (permission === "granted") {
        var notification = new Notification(title, options);
      }
    });
  }
}

var title = "Shiyam Notification";
var options = {
  body: "Shiyam Notification Body",
  icon: "https://shiyamexperience.files.wordpress.com/2016/01/shiyam-croped-low-poly-small.jpg?w=227"
}
notifyMe(title, options);

Reference from codepad.co

Advertisements