I have some code that uses dispatchEvent
to simulate clicks and the same exact code works fine in Chrome but doesn't work in Firefox. Here's the code:
var evt = document.createEvent("MouseEvents");
evt.initEvent("click",true,true);
jQuery("a:contains(Next)")[0].dispatchEvent(evt);
I'm clicking on a link that loads another page and the page loads fine in Chrome but Firefox does absolutely nothing when I run this code in Firebug or even when I execute it as a bookmarklet. I've also tried the long form of event initializing by setting all the options as shown on the MDC docs but that doesn't do anything. What exactly am I doing wrong here?
As your event looks to be a mouse event, you may rather try using a mouse event, like this example :
See W3C Mouse event types
I also wrote a tutorial in French language about firing DOM events ; I guess it's easy to get it translated.
This is a bug in Firefox, see this:
https://bugzilla.mozilla.org/show_bug.cgi?id=395917
I don't know of any way to get around it I'm afraid.