2013-10-18 114 views
0

AIM:打开新选项卡时,扩展程序向服务器发出请求并获取响应并更改图标颜色。Chrome扩展程序后台脚本不能正常工作

background.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缺少任何东西

+2

你必须加载jQuery的才可以使用jQuery方法......('$'是jQuery的)。 –

回答

0

这就是我一直在寻找:

"background": { "scripts": ["assets/js/jquery.min.js","background.js"] ,"persistent": false }, 
相关问题