Skip to content

Instantly share code, notes, and snippets.

@ghooghe
Created November 12, 2013 12:32
Show Gist options
  • Select an option

  • Save ghooghe/7430085 to your computer and use it in GitHub Desktop.

Select an option

Save ghooghe/7430085 to your computer and use it in GitHub Desktop.
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'
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment