0

有人可以告诉我如何将函数 chrome.browserAction.setBadgeText 在 chrome 扩展中的图标下显示数字。该数字需要从 php 文件中的变量中获取,但它可以在 chrome.php 之外的另一个文件中。我的文件:

清单.json:

{
  "name": "Mysite",
  "version": "0.9.1",
  "manifest_version": 2,
  "description": "My Description.",
  "browser_action": {
      "default_icon": "icon.png",
      "default_popup": "chrome.html"
  },
  "permissions": [
    "http://www.mysite.com/",
    "tabs"
  ]
}

铬.html:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>MySite</title>
<script src="ajax.js"></script>
<link rel="stylesheet" href="styles.css" type="text/css" media="all">
</head>
<body>
<div id="resultado" style="font-family: Arial;"></div>
</body>
</html>

ajax.js:

window.onload = function() {
var XHR = new XMLHttpRequest;
chrome.tabs.query({
 active: true,
 currentWindow: true
}, function(tab) {

tabUrl = tab[0].url;
XHR.open('GET', 'http://www.mysite.com/chrome/chrome.php?tab=' + tabUrl + '', true);
XHR.onreadystatechange = function() {
  if(4 == this.readyState) {
    var status = this.status;
    if(400 > status) {
      var responseText = this.responseText;
      if(responseText) {
        document.getElementById('resultado').innerHTML = responseText;

      }
    }
  }
};
XHR.send();
});
};
4

1 回答 1

0

“权限”:[ “http://www.mysite.com/”,“标签”]

匹配模式不正确。请改用“http://www.mysite.com/”*。查看https://developer.chrome.com/extensions/match_patterns.html了解更多信息。

于 2012-11-29T11:40:21.160 回答