Detecting middle mouse click event jQuery

前端 未结 2 940
忘了有多久
忘了有多久 2020-12-20 16:04

I want to show a jQuery-UI dialog box as a popup when user clicks on left mouse button or the middle one. It works for left click (I get the alert box and after that the pop

2条回答
  •  萌比男神i
    2020-12-20 16:19

    To get this working fully in Firefox (40.0.3), I had to implement .on('mouseup', fn), as follows:

    $(selector).on('mouseup', function (e) {
    
        switch (e.which)
        {
            // Left Click.
            case 1:
                // By way of example, I've added Ctrl+Click Modifiers.
                if (e.ctrlKey) {
                    // Ctrl+LeftClick behaviour.
                } else {
                    // Standard LeftClick behaviour.
                }
                break;
    
            // Middle click.
            case 2:
                // Interrupts "Firefox Open New Tab" behaviour.
                break;
    
            // Default behaviour for right click.
            case 3:
                return;
        }
    
        // Pass control back to default handler.
        return true;
    });
    

提交回复
热议问题