2013-10-18 153 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 }, 
相關問題