Last active
December 12, 2015 07:38
-
-
Save EpokK/4737648 to your computer and use it in GitHub Desktop.
Notification HTML5 Chrome Safari
http://www.chromium.org/developers/design-documents/desktop-notifications/api-specification
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
notification : function(sUrl, sTitle, sContent, onDisplay, onClick, onClose) | |
{ | |
if(window.webkitNotifications) { // Test si webkitNotifications de Chrome | |
if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED | |
var notif = window.webkitNotifications.createNotification( | |
sUrl, // icon url - can be relative | |
sTitle, // notification title | |
sContent // notification body text | |
); | |
notif.ondisplay = onDisplay; | |
notif.onclick = onClick; | |
notif.onclose = onClose; | |
notif.addEventListener('display', function() { // On la close au bout de 5 sec | |
window.setTimeout(function() { | |
notif.cancel(); | |
}, 5000); | |
}); | |
notif.show(); | |
} else { | |
// On demande la permission a l'utilisateur | |
window.webkitNotifications.requestPermission(function() { | |
WMailDesign.notification(sUrl, sTitle, sContent, onDisplay, onClick, onClose); | |
}); | |
} | |
} else if(window.Notification) { // Cas Safari | |
if (Notification.permissionLevel() === "granted") { | |
var notif = new Notification(sTitle); | |
notif.show(); | |
} else if (Notification.permissionLevel() === "default") { | |
Notification.requestPermission(function () { | |
WMailDesign.notification(sUrl, sTitle, sContent, onDisplay, onClick, onClose); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment