1

I am trying to trigger a click event on an element on a page from within a Firefox sandbox. I have tried using jQuery's .click() as well as doing:

var evt = document.createEvent("HTMLEvents");
evt.initEvent("click", true, false );
toClick[0].dispatchEvent(evt);

Has anyone been able to trigger a click event on a page in the browser through a sandbox? I can get the DOM element fine, but triggering the event is a different story.

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
Jessie A. Morris
  • 2,267
  • 21
  • 23

1 Answers1

1

You have to create the event on the right document:

var evt = pageDocument.createEvent("HTMLEvents");
evt.initEvent("click", true, false );
toClick[0].dispatchEvent(evt);

The true means the event "bubbles" and the false means the event cannot be cancelled. From https://developer.mozilla.org/en/DOM/event.initEvent

Tyler
  • 21,762
  • 11
  • 61
  • 90
Jessie A. Morris
  • 2,267
  • 21
  • 23
  • I edited your answer to include a description of what the boolean params to initEvent mean, plus a link. Hope you don't mind! – Tyler Jun 26 '10 at 19:42