Search code examples
javascriptfirefox-addondom-events

Javascript event for triggering page-defined javascript function for Firefox extension


I am writing a Firefox extension that needs to write and submit a form with a text type input box, which contains its own onsubmit function. The function is defined in the the target site, which I don't control, so I can't call it directly, and for security reasons it probably shouldn't be called with a kluge-like wrappedJSObject. The page is done in frames, which seems to be leading to odd behaviors - e.g., adding "onchange" events for the form or the input elements isn't triggering anything. I can't simply trigger a submit, since this skips over the on-page submit function.

It has occurred to me that I could write to the input element, and then make some kind of change on the page which would then trigger an event listener which then calls the function. My question is more specifically: what would be the best kind of event to trigger and listen for? onchange doesn't seem to be working when attached to the form or the input element; as far as I know, this is only for forms and form elements. I could listen for an onload event of a 1x1px transparent pixel image; but this sounds very klugey indeed. Has anyone been in a similar predicament, or seen a standard type solution for this kind of challenge?


Solution

  • Getting the submit button, then calling button.click() should both submit the form and trigger onsubmit handler.