Microsoft Edge: onclick event stops working?

前端 未结 4 873
予麋鹿
予麋鹿 2020-12-16 12:36

I have strange problems with my (ASP.NET) web application in Microsoft Edge.

At a certain point the onclick event stops working. All buttons on the pag

4条回答
  •  眼角桃花
    2020-12-16 13:14

    This is not a complete answer, as it doesn't address why click events don't work, but I feel it belongs here, as my team and I were hopelessly stuck trying to find an answer to this question. It appears to be a bug in Edge, and every workaround we tried failed, until I stumbled upon @Come's comment above.

    The solution was to change all of our click events to mouseup events, emulating the same behavior. For some reason mouseup was triggered even when click wasn't. mousedown works as well, but mouseup more-properly emulates click.

    var listenType = (navigator.userAgent.toLowerCase().indexOf('edge') != -1) ? 'mouseup' : 'click';
    
    // ...
    
    $("#my_element").on(listenType, function() 
    {
        // ...
    }
    

    Hopefully this helps someone!

提交回复
热议问题