Skip to content Skip to sidebar Skip to footer

In Jquery, How To Make The Right Click Of The Mouse Have The Same Behavior Of Left Click

what i want to realize is : when I right click a link , it also jump to another page like left click. how to do it? thanks very much.

Solution 1:

There is a plugin that will handle a lot of this for you: http://abeautifulsite.net/blog/2008/05/jquery-right-click-plugin/

Or if you wanted to roll your own:

Check out the docs for event.which: http://api.jquery.com/event.which/

You can detect which mouse button was clicked:

$('.clicky').mousedown(function(event) {
switch (event.which) {
    case1:
    alert('Left mouse button pressed');
    break;
    case2:
    alert('Middle mouse button pressed');
    break;
    case3:
    alert('Right mouse button pressed');
       // you would want to prevent default behavior and trigger a click event.preventDefault();
       $(this).trigger('click');
    break;
    default:
    alert('You have a strange mouse');
}
});

Solution 2:

What have you tried? This is a failrly simple problem with a simple solution..

Connect to the right event and write a handler to accomplish your needs. :)

Post a Comment for "In Jquery, How To Make The Right Click Of The Mouse Have The Same Behavior Of Left Click"