Reputation: 87
I am trying to run a script on page load using pageMod: but I could not see its effect
var data = require("sdk/self").data;
var attachTo = require("sdk/content/mod").attachTo;
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*",
contentScriptWhen: "start",
allow:true,
attachTo: ["existing", "top"],
contentScriptFile: [data.url("jquery-2.1.1.min.js"),
data.url("somejs.js")],
})
Inside my somejs.js file, I have overriden form submit function:
document.forms['frmMain'].submit=function submit(){alert("Submitting")...
...do some stuff
};
On my web page there is a button which submits the form:
frmMain.method="post"
frmMain.action = "someurl";
frmMain.submit();
But When I click button it does not call the overriden method I defined above. When I override the function using firebug console It works! SO what does firebug do to run the command so that I can do same in my addon code to achieve same thing.
Upvotes: 6
Views: 1522
Reputation: 33212
Per Interacting with page scripts you'll
The following works for me:
function submit() {
console.log("Submitting");
alert("Submitting");
};
unsafeWindow.document.forms['frmMain'].submit =
exportFunction(submit, unsafeWindow);
Upvotes: 3