在头部注入脚本代码

时间:2015-08-20 13:24:28

标签: javascript jquery firefox-addon

我尝试使用我的Firefox插件将脚本代码作为document.head的子代素注入。

\铬\内容\ test.js:

function test() {
    var injTest = document.createElement('script');
        injTest.innerHTML = ["alert('test')"].join('\n');
    (document.head||document.documentElement).appendChild(injTest);
}
test();

但它不起作用。我还需要做什么?

在Chrome扩展程序中,它可以正常运行:

manifest" content_scripts":

  ///
  "content_scripts": [
    {
      "matches": ["*://example.com/*"],
      "js": ["jquery-1.11.3.min.js", "content_script.js"],
      "run_at": "document_start"
    }
  ],
  ///

content_script:

function test() {
    var injTest = document.createElement('script');
        injTest.innerHTML = ["alert('test')"].join('\n');
    (document.head||document.documentElement).appendChild(injTest);
}
test();

0 个答案:

没有答案
相关问题