Skip to content

Instantly share code, notes, and snippets.

@typeofweb
Last active October 7, 2015 21:08
Show Gist options
  • Save typeofweb/3225321 to your computer and use it in GitHub Desktop.
Save typeofweb/3225321 to your computer and use it in GitHub Desktop.
Web Notifications
var showNotification = function (data) {
if (window.webkitNotifications) {
if (!webkitNotifications.checkPermission()) {
var notif = webkitNotifications.createNotification(data.icon, data.title, data.body);
notif.show();
} else {
webkitNotifications.requestPermission(function () {
showNotification(data);
});
}
}
else if (window.Notification) {
if (Notification.permissionLevel() === "granted") {
var notif = new Notification(data.title, data);
notif.show();
} else if (Notification.permissionLevel() === "default") {
Notification.requestPermission(function () {
showNotification(data);
});
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment