Triggering click events from within a FF sandbox
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 sa开发者_Go百科ndbox? I can get the DOM element fine, but triggering the event is a different story.
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
精彩评论