有人可以告诉我如何将函数 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();
});
};