Notifications

Notifications

by Warwick Grigg

JavaScript

function notifyMe(title, options) {
	var notinner = function(title, options) {
		var n = new Notification(title, options);
    setTimeout(n.close.bind(n), 5000);
  }
  // Let's check if the browser supports notifications
  if (("Notification" in window)) {
  	if (Notification.permission === "granted") {
    	notinner(title, options);
    } else if (Notification.permission !== 'denied') {
    	Notification.requestPermission(function (permission) {
      	if (permission === "granted") {
        	notinner(title, options)
      	}
    	});
  	}
  }
}

notifyMe("Title", {body: "body", tag: "tag"});