admin管理员组文章数量:1417662
I can set a badge text in chrome extension by below api
chrome.browserAction.setBadgeText({text: '<number_of_new_teets>'});
How can I get the badge text that I have set before ?
I can set a badge text in chrome extension by below api
chrome.browserAction.setBadgeText({text: '<number_of_new_teets>'});
How can I get the badge text that I have set before ?
Share Improve this question asked Dec 19, 2013 at 16:12 user862226user862226 1292 silver badges8 bronze badges3 Answers
Reset to default 5Use chrome.browserAction.getBadgeText
:
chrome.browserAction.getBadgeText({}, function(result) {
alert('Badge text = ' + result);
});
This method (like most of the Chrome extension API) is asynchronous, so you need to specify a callback function that receives the result.
Answer by Rob W is returning blank result
for all tabs. Adding tab.id
worked for me:
chrome.browserAction.getBadgeText({ tabId: activeTab.id }, result => {
alert('Badge text = ' + result);
});
In the Chrome extension API v3, the chrome.browserAction API has been replaced with the chrome.action API.
To set the badge text:
chrome.action.setBadgeText({text: '<number_of_new_tweets>'});
To get the badge text:
chrome.action.getBadgeText({}, function(result) {
var badgeText = result;
console.log("Badge text: " + badgeText);
});
The usage is similar to the v2 API, but note that chrome.action is used instead of chrome.browserAction in Chrome extension API v3.
本文标签: javascriptget badge text that set before in chrome extensionStack Overflow
版权声明:本文标题:javascript - get badge text that set before in chrome extension - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745278433a2651309.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论