Working with NotificationUI on browsers with HTML5

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.

 

Abhishek Sur

Abhishek Sur is a Microsoft MVP since year 2011. He is an architect in the .NET platform. He has profound theoretical insight and years of hands on experience in different .NET products and languages. He leads the Microsoft User Group in Kolkata named KolkataGeeks, and regularly organizes events and seminars in various places for spreading .NET awareness. He is associated with the Microsoft Insider list on WPF and C#, and is in constant touch with product group teams. He blogs at http://www.abhisheksur.com His Book : Visual Studio 2012 and .NET 4.5 Expert Development Cookbook. Follow Abhishek at Twitter : @abhi2434

2 Comments to “Working with NotificationUI on browsers with HTML5”

  1. 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. 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.