开发者

setting a badge in my chrome extension

开发者 https://www.devze.com 2023-04-01 23:03 出处:网络
Hi I have this code in my background.html file, but it does not seem to be working function setBadge(tab) {

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消