How to block "open in a new tab" clicks in jquery.click

I have a jquery script that attaches a click event to each link, triggering an action when the link is clicked. This works great, but I just got some feedback about the bettors who were bothering me.

The user right-clicked on the link and opened it in a new tab. When she did this, jquery did not catch the click. BAD USER. I reproduced this with cmd-click.

Is there a way to catch these gestures, or is it an inherent restriction?

+5
source share
3 answers

So you want to capture every click? Is the event right or middle? Should a mousedown event do this?

Of course, she could right-click the link only for "Copy link location" ...

+1
source

See if you can somehow use the jQuery rightclick plugin:

http://abeautifulsite.net/notebook/68

Using:

$(document).ready( function() {

    // Capture right click
    $("#selector").rightClick( function(e) {
        // Do something
    });

    // Capture right mouse down
    $("#selector").rightMouseDown( function(e) {
        // Do something
    });

    // Capture right mouseup
    $("#selector").rightMouseUp( function(e) {
        // Do something
    });

    // Disable context menu on an element
    $("#selector").noContext();

});

Regarding the cmd-clickie bit, I'm really not sure. In case this is useful, here is the jQuery hotkeys plugin:

http://www.webappers.com/2008/07/31/bind-a-hot-key-combination-with-jquery-hotkeys/

+2
source

jquery.rightclick.js firebug. mousedown mouseup, :

Alt ctrlKey

so you can use these two modifiers:

if (evt.altKey || evt.ctrKey)

in jquery.rightclick.js

0
source

All Articles