Navigator: setAppBadge() メソッド

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Navigator インターフェイスの setAppBadge() メソッドは、このアプリケーションに関連付けられたアイコン上のバッジを設定します。メソッドに値を渡した場合は、この値をバッジの値として設定します。値を渡さなかった場合は、バッジは点、もしくはプラットフォームで定義されたその他の表示になります。

構文

js
setAppBadge()
setAppBadge(contents)

引数

contents 省略可

バッジの値として用いる number です。contents0 の場合は、バッジは nothing に設定され、非表示になります。

返値

undefined で解決する Promise を返します。

例外

NotSupportedError DOMException

Navigator に操作を実行する対象のドキュメントが無いとき投げられます。

以下の例では、未読カウントを setAppBadge() に渡します。その結果、バッジは 30 を表示するはずです。

js
const unread = 30;
navigator.setAppBadge(unread);

仕様書

Specification
Badging API
# setappbadge-method

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
setAppBadge

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

関連情報