Created
December 19, 2013 23:00
-
-
Save mattbasta/8047702 to your computer and use it in GitHub Desktop.
This file contains 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
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