Skip to content

Instantly share code, notes, and snippets.

@EpokK
Last active December 12, 2015 07:38
Show Gist options
  • Save EpokK/4737648 to your computer and use it in GitHub Desktop.
Save EpokK/4737648 to your computer and use it in GitHub Desktop.
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