目的:打开新标签后,扩展程序会向服务器发出带有URL的请求,并获取响应并更改图标颜色。
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 ");
});
});
}
这会将网址发送到我的本地服务器!background.js是否缺少任何内容
这就是我想要的:
"background": { "scripts": ["assets/js/jquery.min.js","background.js"] ,"persistent": false },
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句