docs.rodeo

MDN Web Docs mirror

Badging API

{{DefaultAPISidebar("Badging API")}} {{securecontext_header}} {{AvailableInWorkers}} 

The Badging API gives web developers a method of setting a badge on a document or application, to act as a notification that state has changed without displaying a more distracting notification. A common use case for this would be an application with a messaging feature displaying a badge on the app icon to show that new messages have arrived.

Concepts and Usage

Web developers frequently update document favicons or titles in order to indicate status. The Badging API provides a more elegant way to show status, by providing a method which has meaning to the user agent and can therefore be displayed in a way that matches the rest of the UI.

Types of badges

There are two types of badges:

Badge states

A badge can have one of three possible values, which are set internally:

Setting badges

A badge is set with the methods setAppBadge() (for installed apps). If no parameters are passed to these methods then the badge value is flag. The user agent will display its notification badge, for example, a colored circle on the icon.

These methods can also be passed a parameter contents, which should be a number. This will then be displayed as part of the badge. User agents may change this value in some way. For example, if you pass a very large number such as 4000, the user agent may display this as 99+ in the badge. User agents may also ignore this data and display a marker instead.

Clearing badges

Badges are cleared with the clearAppBadge() methods. These do not take any parameters and set the badge to the value nothing. Additionally, passing a value of 0 to setAppBadge() will set the badge to nothing and clear the badge.

Interfaces

None.

Extensions to the Navigator interface

Extensions to the WorkerNavigator interface

Examples

To set a notification badge on the current app with a value of 12:

navigator.setAppBadge(12);

To clear a notification badge on the current app:

navigator.clearAppBadge();

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN