仅在设置了首选项时才在内容脚本中加载jQuery

时间:2011-12-03 15:51:43

标签: javascript google-chrome-extension

我有谷歌浏览器扩展程序。

我想在我的内容脚本中加载jQuery。 如果我发货jquery.js并更改清单

,这很容易
{
  "name": "My extension",
  ...
  "content_scripts": [
    { "js": ["jquery.js", "myscript.js"], ...    }
   ],
...
}

现在,只有当用户选中了选项页面中的相应选项时,我才需要jQuery。

为了优化我的代码,我怎样才能在需要时在我的内容脚本中加载jQuery?

1 个答案:

答案 0 :(得分:0)

使用chrome.tabs.executeScript。 content_script documentation page上有一个示例。