Navigator.setAppBadge()
The setAppBadge()
method of the Navigator
interface a badge on the icon associated with this app. If a value is passed to the method, this will be set as the value of the badge. Otherwise the badge will display as a dot, or other indicator as defined by the platform.
Syntax
let promise = Navigator.setAppBadge(contents);
Parameters
-
contents
Optional -
A
number
which will be used as the value of the badge. Ifcontents
is0
then the badge will be set tonothing
, indicating a cleared badge.
Return value
A Promise
that resolves with undefined
.
Exceptions
-
NotSupportedError
DOMException
-
The
Navigator
does not have a document that this action can be acted on.
Examples
In the example below an unread count is passed to setAppBadge()
. The badge should then display 30
.
const unread = 30; navigator.setAppBadge(unread);
Specifications
Specification |
---|
Badging API # setappbadge-method |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
setAppBadge |
83
Windows and Mac only.
|
83
Windows and Mac only.
|
No |
No |
No |
No |
No |
No |
No |
58 |
No |
13.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/setAppBadge