1

I am toying around with the firefox sdk add on right now, and I want to add javascript files to an existing website - like adding jquery to an existing website.

How do I do that?

1
  • do you own the website page? or is this a 3rd party website? Commented Oct 28, 2015 at 1:57

1 Answer 1

1

There are some solutions to do that. One example is the following:

var tabs = require("sdk/tabs");
var data = require("sdk/self").data;

tabs.on('ready', function(tab) {
    var worker = tabs.activeTab.attach({
        contentScriptFile: [
            data.url("jquery.min.js")
        ]
    }); 
});

Where the jquery.min.js is in your data folder of your extension and it will attached to the active tab.

One other solution is to use pageMod that it will allow you to determine in which web pages the JS will attached. In the following example it will attached to mozilla.org.:

var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");

pageMod.PageMod({
  include: "*.mozilla.org",
  contentScriptFile: data.url("my-script.js")
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.