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?
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?
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")
});