【问题标题】:number under chrome extension iconchrome 扩展图标下的数字
【发布时间】:2012-11-27 14:12:05
【问题描述】:

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

manifest.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"
  ]
}

chrome.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();
});
};

【问题讨论】:

  • 你的后台页面中有这段代码吗?它位于哪里?在 readystatechange 处理程序中使用 chrome.browserAction.setBadgeText(responseText) 不起作用吗?
  • 我已经编辑了我的帖子,添加了我拥有的所有文件(只是没有 PHP 文件,因为我认为 PHP 文件在这个问题中并不重要)。

标签: php javascript google-chrome-extension icons


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 2013-08-11
    • 2014-10-12
    • 1970-01-01
    相关资源
    最近更新 更多