setting a badge in my chrome extension
Hi I have this code in my background.html file, but it does not seem to be working
function setBadge(tab) {
$.get("getUrlLikes.php", { url: tab.url }, function(data) {
开发者_StackOverflow中文版 chrome.browserAction.setBadgeText({
text: String(data)
});
});
}
chrome.browserAction.onClicked.addListener(null, function(tab) {
setBadge(tab);
});
onClicked
has one parameter, not two. It should be:
chrome.browserAction.onClicked.addListener(setBadge);
Unless you mean pageAction
?
Also you need to make sure that browser action doesn't have a popup assigned to it, otherwise onClicked
won't fire.
Is anything actually returning from that $.get("getUrlLikes.php"
call? You probably need to point it at http://mydomain.com/getUrlLikes.php
.
$.get
is a jQuery-ism. Have you loaded jQuery?
精彩评论