Web Notifications Api
W3C Last Call Working Draft 12 September 2013
HTML
<title>Web Notifications Api</title>
<body>
<input id="btnNotification" type="button" value="Notification" />
</body>
JavaScript
window.addEventListener('load', function () {
function getPermission() {
if ("Notification" in window && Notification.permission !== "denied") {
Notification.requestPermission(function (status) {
if (Notification.permission !== status) Notification.permission = status;
});
}
}
getPermission(); //Only Firefox
document.addEventListener("click", getPermission);
var btnNotification = document.getElementById('btnNotification');
btnNotification.addEventListener("click", function () {
if ("Notification" in window && Notification.permission === "granted") {
var icon = "http://www.returngis.net/wp-content/uploads/pics/2012/11/angry-bird-icon.png",
bodyMessage = "This is my body message!",
notification = new Notification("Notification!", {
icon: icon,
body: bodyMessage
});
notification.onshow = function () {
setTimeout(function () {
notification.close();
}, 3000);
};
notification.onclose = function () {
console.log("notification.onclose fired");
};
notification.onerror = function () {
console.log("notification.onerror fired");
};
notification.onclick = function () {
console.log("notification.onclick fired");
};
}
});
});