Notifications to the desktop are nothing new, but notifications on the browser are.
The OSX folks have had something called Growl notifications in place, which requires installation, then could be accessed through the windows.fluid object built into Safari on Mac.
Google, with their support for Web Notifications, and their W3C recommendation in general, have tried standardizing this concept.
Here's a small working example for the same:
PS: Try it, in baby steps, on Jash. FUN!
A simplified concept, a small API, and user security considerations - the spec has its bases covered. Presently these notifications only work on the Chrome browser across Windows and Linux.<script type="text/javascript">
(function() {
var notificationStatus;
setupNotifications = function() {
if(window.webkitNotifications) {
if(window.webkitNotifications.checkPermission() == 0 ) { //permission granted
notificationStatus = 'Permission granted';
} else if(window.webkitNotifications.checkPermission() == 1 ) { //permission unknown
//notificationStatus = 'Permission not granted yet';
notificationStatus = "Unknown, click to <a href='javascript:window.webkitNotifications.requestPermission(setupNotifications);'>enable web notifications</a>.";
window.webkitNotifications.requestPermission(setupNotifications);
} else { //permission denied
notificationStatus = 'Permission denied';
}
} else alert('Not supported');
if(!!document.getElementById("notificationStatus"))
document.getElementById("notificationStatus").innerHTML = notificationStatus;
}
notifyMe = function() {
//permission already granted
if(window.webkitNotifications.checkPermission() == 0 ) {
var popup = window.webkitNotifications.createNotification(
"myicon.ico",
"You nailed it",
"My good sir, by delving into this notification thingy you open yourself to plenty of bobfoolery"
);
//ondisplay is one of the three events for the notification API
// ondisplay, onerror, oncancel
popup.ondisplay = function() {
setTimeout(function () {popup.cancel();}, 6000);
//we keep a timeout for the notification, since they don't have one by default
};
popup.show(); //this displays the notification
}
}
window.onload = setupNotifications;
})();
</script>
For the old crowd, things were ridiculous, with the programmers having to resort to annoying and invasive hacks like window.alert. This new feature would give online tools like e-mail clients, calendering software, task managers, monitoring systems, etc. an elegant and consistent way to notify users.
However, not everybody is gaga over it. After some toying around, even I am a bit skeptical about the specs and the architecture: The notifications take a while to associate with their tab. They aren't a welcome experience to deal with when your friends start firing messages in your gmail chat window. Moreover, with the proliferation of these (among Tier 1 sites, to merely begin with) we can only anticipate an avalanche of these, since the recommendation suggests no way to restrict or control the notifications.
No comments:
Post a Comment