【问题标题】:Chrome Extension background script not workingChrome 扩展后台脚本不起作用
【发布时间】:2014-01-23 23:18:19
【问题描述】:

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 是否缺少任何东西

【问题讨论】:

  • 您必须先加载 jQuery,然后才能使用 jQuery 方法...($ 是 jQuery)。

标签: google-chrome google-chrome-extension


【解决方案1】:

这就是我要找的:

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

【讨论】:

    猜你喜欢
    • 2020-07-13
    • 2018-04-11
    • 1970-01-01
    • 2016-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多