How to continue event propagation after cancelling?

前端 未结 8 688
孤街浪徒
孤街浪徒 2020-12-13 11:41

When a user clicks a certain link I would like to present them with a confirmation dialog. If they click \"Yes\" I would like to continue the original navigation. One catch:

相关标签:
8条回答
  • 2020-12-13 12:45

    If I am understanding the problem correctly, I think you can just update the event to be the original event in that closure you have there. So just set e = e.originalEvent in the .done function.

    https://jsfiddle.net/oyetxu54/

    MyApp.confirm("confirmation?")
    .done(function(){ e = e.originalEvent;})
    

    here is a fiddle with a different example (keep the console open so you can see the messages): this worked for me in chrome and firefox

    0 讨论(0)
  • 2020-12-13 12:48

    Below are the bits from the code that actually worked in Chrome 13, to my surprise.

    function handler (evt ) {
        var t = evt.target;
        ...
        setTimeout( function() {
            t.dispatchEvent( evt )
        }, 1000);
        return false;
    }
    

    This is not very cross-browser, and maybe will be fixed in future, because it feels like security risk, imho.

    And i don't know what happens, if you cancel event propagation.

    0 讨论(0)
提交回复
热议问题