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缺少任何東西
你必須加載jQuery的纔可以使用jQuery方法......('$'是jQuery的)。 –