Skip to content

Instantly share code, notes, and snippets.

@mattbasta
Created December 19, 2013 23:00
Show Gist options
  • Save mattbasta/8047702 to your computer and use it in GitHub Desktop.
Save mattbasta/8047702 to your computer and use it in GitHub Desktop.
function notify(title, body, icon, callback) {
if (window.Notification) {
function donotify() {
var notification = new Notification(title, {
body: body,
icon: icon
});
notification.onclick = callback;
}
if (Notification.permission === 'granted') {
donotify();
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function(permission) {
if (permission !== 'granted') return;
donotify();
});
}
} else {
var havePermission = window.webkitNotifications.checkPermission();
if (havePermission === 0) {
var notification = window.webkitNotifications.createNotification(
icon || null,
title,
body
);
notification.onclick = callback;
notification.show();
} else {
window.webkitNotifications.requestPermission();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment