Last active
October 7, 2015 21:08
-
-
Save typeofweb/3225321 to your computer and use it in GitHub Desktop.
Web Notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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