Working with NotificationUI on browsers with HTML5

By | June 13, 2012

Notification is one of the interesting thing that browsers are adding support to. Generally when we think of Web notification we always go for some HTML popup or using a new window through Javascript. But those html are generally does not follow any standards or even looks different to the user to different sites. Hence few of the notifications lacks consistency. HTML5 introduces new notification specs which enable the browser to send its own notification rather than going with custom notifications from the developer.

The notifications is now currently implemented in Chrome, but it will be implemented in latest releases of other browsers too. Let us look how to use notification  in your browser.

To request for notification use the following code :

window.webkitNotifications.requestPermission();

When the browser asks for notification, it will popup one message to the user to allow or deny. If the user allows the notification, the notification service gets enabled and the site can send notification to the browser.

if (window.webkitNotifications.checkPermission() == 0) {
var notification = window.webkitNotifications.createNotification(imgpath, 'Notification received', 'Hii, this is special notification');
notification.show();
}

So when we use createNotification it will create a notification object with the image , title and the message which needs to be notified. The show() method will show the notification to the user.

 

Thats all folks, Hope you find this interesting.

 

2 thoughts on “Working with NotificationUI on browsers with HTML5

  1. Tykarz13

    I feel this is one of the such a lot vital information for me. And i am glad studying your article. However should commentary on some common things, The site taste is great, the articles is in reality excellent : D. Just right process, cheers.

  2. RAVI SATYADARSHI

    Hey Abhishek. Thanks for this useful information u have shared with us. I would like to request you to post the complete code to use this notification feature so that everyone can know how to use this.
    I mean to say where we would write this line of code to execute.

Comments are closed.