var canNotify = function() {
if ("Notification" in window) {
if (Notification.permission === 'granted') {
return true;
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if(!('permission' in Notification)) {
Notification.permission = permission;
}
// If the user is okay, let's create a notification
if (permission === "granted") {
return true;
}
});
}
}
return false;
};
var notify = function(message) {
if (canNotify()) {
new Notification('Title', {
tag: 'notification-id',
body: message,
icon: 'icon-url'
});
}
};