AIM:当打开任何新的选项卡时,扩展会向服务器发出带有url的请求,并获得响应并更改图标颜色。
背景.js:
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab)
{
url = "http://localhost/test.php?"+ $.param({"url":tab.url});
$.get(url, function(responseText) {
console.log("sent data");
});
});
manifest.json:
..."background": { "scripts": ["background.js"] ,"persistent": false },
"permissions": ["tabs","http://localhost/", "http://*/*"],....
这行不通。
但当与扩展页上的按钮绑定为:
function send_url(){
chrome.tabs.getSelected(null,function(tab){
url = "http://localhost/test.php?"+ $.param({"url":tab.url});
$.get(url, function(responseText) {
console.log("url sent ");
});
});
}
这会将url发送到我的本地服务器!
background.js缺少什么吗