Skip to content Skip to sidebar Skip to footer

Firefox 5 DispatchEvent In Firefox

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.createEven

Solution 1:

As your event looks to be a mouse event, you may rather try using a mouse event, like this example :

var oEvt = (document.createEvent)? document.createEvent('MouseEvents') : document.createEventObject();    
       // W3C
        if (oEvt.initMouseEvent) 
            oEvt.initMouseEvent(
                /* type*/            'mouseup',
                /* bubble*/            true,
                /* cancel*/            true,
                /* AbstractView*/     window,
                /* detail */        10,
                /* screenX */        20,
                /* screenY */        30, 
                /* clientX */        40,
                /* clientY */        50,
                /* ctrlKey */        false,
                /* altKey */        false,
                /* shiftKey */        true,
                /* metaKey */        false,
                /* button */        0,
                /* relatedTarget*/    null ) ;
        // MSIE
        else {
                var oEvt = document.createEventObject(); 
                oEvt.detail = 10;
                oEvt.screenX = 20;
                oEvt.screenY = 30;
                oEvt.clientX = 40;
                oEvt.clientY = 50;
                oEvt.ctrlKey = false;
                oEvt.altKey = false;
                oEvt.shiftKey = true;
                oEvt.metaKey = false;
                oEvt.button = 0;
                oEvt.relatedTarget = null;
        }

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.


Solution 2:

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.


Post a Comment for "Firefox 5 DispatchEvent In Firefox"