Created
September 23, 2012 08:12
-
-
Save aorcsik/3769318 to your computer and use it in GitHub Desktop.
HTML5 Notifications
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
document.write('<input id="shownoti" style="display: none;" type="button" value="Show Notification" />'); | |
document.write('<div style="display: none;" id="notidenied">Az értesítések megjelenítését letiltottad!</div>'); | |
var displayNotiButton = function() { | |
if (window.webkitNotifications.checkPermission() == 0) { | |
document.getElementById("shownoti").onclick = function() { | |
var notification = webkitNotifications.createNotification("icon.png", "blog.intiweb.hu", "Értesítve vagy!"); | |
notification.addEventListener('display', function() { | |
window.setTimeout(function() { | |
notification.cancel(); | |
}, 5000); | |
}); | |
notification.show(); | |
}; | |
document.getElementById("shownoti").style.display = "inline"; | |
return true; | |
} else if (window.webkitNotifications.checkPermission() == 2) { | |
document.getElementById("notidenied").style.display = "block"; | |
return true; | |
} else if (window.webkitNotifications.checkPermission() == 1) { | |
return false; | |
} | |
}; | |
if (window.webkitNotifications) if (false === displayNotiButton()) { | |
document.write('<input type="button" value="Request Notification Permission" id="reqperm">'); | |
document.getElementById("reqperm").addEventListener('click', function() { | |
window.webkitNotifications.requestPermission(function() { | |
document.getElementById("reqperm").style.display = "none"; | |
displayNotiButton(); | |
}); | |
}); | |
} |
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
if (window.webkitNotifications.checkPermission() == 0) { | |
/* API kód */ | |
} else if (window.webkitNotifications.checkPermission() == 1) { | |
document.write('<input id="reqperm" type="button" value="Request Notification Permission" />'); | |
document.getElementById("reqperm").addEventListener('click', function() { | |
window.webkitNotifications.requestPermission(function() { | |
/* API kód */ | |
}); | |
}); | |
} |
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
var notification = webkitNotifications.createNotification("icon.png", "blog.intiweb.hu", "Értesítve vagy!"); | |
notification.addEventListener('display', function() { | |
window.setTimeout(function() { | |
notification.cancel(); | |
}, 5000); | |
}); | |
notification.show(); |
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
if (window.webkitNotifications) { /* ... */ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment