none
IE10 dispatchEvent calls wrong listeners RRS feed

  • Question

  • Hi all,

    I am having a strange problem in a web application running on IE10 (same behavior in Windows 8 or Window 7 preview).

    My application creates and dispatches native events using these calls:

    var e = document.createEvent("HTMLEvents");
    e.initEvent("myEventType", true, true);
    element.dispatchEvent(e);
    

    That works most of the time and correctly calls the listeners registered for the specified event type, but in some rare cases this causes wrong event listeners to be called: listeners that were added for a completely different event type are called, and the "right" event listeners are not called.

    Has anybody seen dispatchEvent going crazy like this on IE10? Is this a known bug?

    Thanks for any help/hints... ;^)

        Eric

    Wednesday, December 5, 2012 9:26 AM

Answers

All replies

  • Hi Eric,

    Thanks for your post.

    I would like to suggest you submit you feedback at http://connect.microsoft.com/ie , please note that when submitting a bug/feedback report include a link to a publicly accessible website that reproduce the issue.


    Yanping Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Yanping Wang Wednesday, December 12, 2012 7:04 AM
    Friday, December 7, 2012 8:06 AM
  • Hi,

    see http://connect.microsoft.com/IE/SearchResults.aspx?SearchQuery=dispatchevent

    which does not list any known issues with dispatchevent and IE10.

    "That works most of the time".... "in some rare cases".....suggests its your code or data.. f12>Script tab, click "Start Debugging"... you should be able to place breakpoints in the event handlers.... do you cancel the event bubble?

    your first line in the event handler should be

    if(!e){e=window.event}


    Rob^_^

    • Marked as answer by Yanping Wang Wednesday, December 12, 2012 7:04 AM
    Friday, December 7, 2012 11:40 PM
  • I am able to replicate this issue.

    1. clear IE10 of all data

    2. close browser and re open

    3. run this HTML page

     

    <html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <title>IE Test</title>
            <script type="text/javascript">
                function listenerB(evt){
                    console.log('listenerB - type :'+evt.type);
                }
                function setListeners(){
                    var aDiv = document.getElementById('aDiv');
                    aDiv.addEventListener("eventB",listenerB,false);
                    console.log('aDiv.addEventListener("eventB",listenerB,false);');
                }
                function sendEvents(){
                    var aDiv = document.getElementById('aDiv');
                    sendEvent("eventA", aDiv, {div:'aDiv'});
                    sendEvent("eventB", aDiv, {div:'aDiv'});
                }
                function sendEvent(type, node, props){
                    if (node){
                        var aEvent = document.createEvent("UIEvent");
                        aEvent.initEvent(type, false, false);
                        if (props){
                            for (i in props){
                                aEvent[i] = props[i];
                            }
                        }
                        console.log('-- EVENT '+type+' / '+node.id+' / '+props[i]);
                        node.dispatchEvent(aEvent);
                    }
                }
            </script>
        </head>

        <body>
                <a href="javascript:setListeners()">Set Listeners</a>
                <br>
                <a href="javascript:sendEvents();">Send Events</a>
                <div id="aDiv">
                    This is div
                </div>
        </body>

    </html>

    4. Click "Set Listeners"

    5. Click "Send Events"

    6. View the console log

    On viewing the console log I can see that the function listenerB was fired from eventA. However the function listenerB was added as a listener to eventB.

    Anyone got any ideas on this?

    Thanks

    Andrew

    Thursday, September 5, 2013 2:45 PM