views:

712

answers:

3

Good morning -

I have a jquery script that attaches a click event to every link, running an action when the link is clicked. This has been working great, but I just got some betatester feedback that's foiling me.

The user was right-clicking on the link and opening it in a new tab. When she did this, jquery didn't trap the click. BAD USER. I reproduced this with cmd-click as well.

Is there a way to trap these gestures, or this an inherent limitation?

Thanks for all your help,

Jason

+2  A: 

See if you can somehow make use of jQuery rightclick plugin:

http://abeautifulsite.net/notebook/68

Usage:

$(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();

});

As for the cmd-clickie bit, I'm really not sure. In case it's helpful, here's the jQuery hotkeys plugin:

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

karim79
That doesn't address the cmd+click though, does it?
Jonathan Sampson
I've added a link to a resource that might be helpful for that purpose, but I'm really not sure just how useful it might be.
karim79
+1 for great links. Think hotkeys should solve problem
TheVillageIdiot
Don't forget middle-click!
Blorgbeard
Yes, and there's also the touch-nose-elbow-reverse-click, but I can't seem to find a suitable plugin :P
karim79
+1  A: 

So you want to capture every click? Event the right or middle one? Shouldn't the mousedown event do just that?

Of course, she could right click a link just to "Copy Link Location"...

Ionuț G. Stan
I ended up going this way. This captures all the clicks, which is exactly what I wanted. It also ended up simplifying the rest of the code. Thank you!
Jason Butler
A: 

I've seen jquery.rightclick.js code in firebug. There are modifiers with the mousedown and mouseup event like:

altKey ctrlKey

so you can use these two modifiers:

if(evt.altKey || evt.ctrKey)

in jquery.rightclick.js

TheVillageIdiot