Issue with onClick() and middle button on mouse

后端 未结 3 508
执笔经年
执笔经年 2020-12-20 23:42
\" onClick=\"countLinks(\'\',\'\')\">[Link ]

The pr

3条回答
  •  礼貌的吻别
    2020-12-20 23:55

    The behavior of this is quite variable by browser. See https://code.google.com/p/chromium/issues/detail?id=255#c106 . According to that, of the ones you asked about:

    • "IE doesn't fire a click event if the target is a link, but does fire it if another element is clicked even if it's a descendant of a link."

    • "Gecko always fires a click event on the document that bubbles and has as target the element being clicked."

    For Firefox, thus you can do:

    $( document ).click(
      function ( evt ) {
        // ... evt.which === 2 means middle click
      }
    );
    

    which is kind of a trick (normally you would listen to events on the link itself), but it works.

提交回复
热议问题