2

Does anyone know the jquery code to perform the action of a left click button when right mouse button is clicked

For Example: Say I right click on a link , instead of opening a pop up window I need it to go the link's destination . In other wants I need the right click to do the action of a mouse left click .

Tried searching the web , but was of no use . Hence posting this as my last option .

Would really appreciate any help .

Thanks in advance .

jat
  • 6,940
  • 3
  • 14
  • 10
  • Possible duplicate, Just check out the following link from stackoverflow http://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery – vivek salve Nov 19 '12 at 05:37
  • @viveksalve Both issues are different – jat Nov 19 '12 at 05:43
  • This seems like a bad UI design. Right click is supposed to bring up a menu of actions to perform on the link, you're taking away the user's ability to choose preferred behavior, such as opening the link in a new tab. – Barmar Nov 19 '12 at 06:13
  • @Barmar Yes. But its one of our clients requirement . – jat Nov 19 '12 at 06:17

2 Answers2

0

Try

$('a').on('contextmenu', function(e){
    window.location = this.href;
    return false;
});

DEMO

Musa
  • 96,336
  • 17
  • 118
  • 137
0
$('#element').mousedown(function(event) {
    if (event.which==3) {
        $('#element').trigger('click');
         break;
       }
});
Amit Garg
  • 3,867
  • 1
  • 27
  • 37