Sets the badge text for the browser action. The badge is displayed on top of the icon.
Tabs without an specific badge text will inherit the global badge text, which is
""
默认情况下。
browser.browserAction.setBadgeText(
details
// object
)
This API is also available as
chrome.browserAction.setBadgeText()
.
details
An object with the following properties:
text
string
or
null
. Any number of characters can be passed, but only about four can fit in the space.
Use an empty string -
""
- if you don't want any badge.
若
tabId
被指定,
null
removes the tab-specific badge text so that the tab inherits the global badge text. Otherwise it reverts the global badge text to
""
.
若
windowId
被指定,
null
removes the window-specific badge text so that the tab inherits the global badge text. Otherwise it reverts the global badge text to
""
.
tabId
可选
integer
. Set the badge text only for the given tab. The text is reset when the user navigates this tab to a new page.
windowId
可选
integer
. Set the badge text for the given window.
windowId
and
tabId
are both supplied, the function fails.
windowId
and
tabId
are both omitted, the global badge is set.
BCD tables only load in the browser
Add a badge indicating how many times the user clicked the button:
var clicks = 0;
function increment() {
browser.browserAction.setBadgeText({text: (++clicks).toString()});
}
browser.browserAction.onClicked.addListener(increment);
注意:
This API is based on Chromium's
chrome.browserAction
API. This documentation is derived from
browser_action.json
in the Chromium code.
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.
最后修改: , 由 MDN 贡献者