Tag Archives: windows 8

Updating the badge in a Windows 8 JavaScript App

Windows 8 apps can have notification badges in the tiles. It’s easy to update the badge, but it’s still not well documented, so here is a small snippet to show you how it’s done:

var Notifications = Windows.UI.Notifications;
var updater = Notifications.BadgeUpdateManager.createBadgeUpdaterForApplication();
var xml = Notifications.BadgeUpdateManager.getTemplateContent(
    Notifications.BadgeTemplateType.badgeNumber
);

xml.getElementsByTagName('badge')[0].setAttribute('value', 5);

var notification = Notifications.BadgeNotification(xml);
updater.update(notification);

Replace the 5 in line 7 with the number of your choice. The end result looks like this:

Badge update example

More info on badge updates is available in the Windows.UI.Notifications namespace of the WinRT and the Badge Update XML Schema.