Reputation: 1671
I'm trying to write my first Firefox extension using the FF add-on builder. I don't understand why it seems my code isn't running at all as neither alert
pops up. Why doesn't alert("Main");
create a popup?
main.js
alert("Main");
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*",
contentScriptFile: data.url("noredirectlinks.js"),
contentScriptWhen: "ready"
});
noredirectlinks.js
alert("Content script");
var allLinks = document.getElementsByTagName("a");
for (var i=0, il=allLinks.length; i<il; i++) {
elm = allLinks[i];
if (elm.getAttribute("onclick")) {
elm.onclick = null;
}
if (elm.getAttribute("onmousedown")) {
elm.onmousedown = null;
}
}
Upvotes: 0
Views: 969
Reputation: 11807
The alert
in main.js
cannot show anything in your browser. The main addon code has not access to the browser page. To access to the content, you have to use content scripts (as your second script).
The alert
in noredirectlinks.js
should work. I would first test again without the alert
in main.js
. Then you must be sure that the file is located in data
folder. Is it the case?
There could be also another error in a code you didn't provide which could explain why the addon is not executed. Is there other code or is that everything?
Upvotes: 1