0

i've got a context menu plugin that will show a context menu when right clicking an element. but that doesnt work on ajax embedded elements. so i have to use ajax live that trigger the context menu function when it senses a right click.

is there a plugin for jquery detecting right clicks?

ajsie
  • 77,632
  • 106
  • 276
  • 381

2 Answers2

7

Try this block of code:

$("body").mousedown(function(e) {
  var code = ( e.keyCode ? e.keyCode : e.which );

  if( code === 3 ) {
    // do your right-click code here
  }
});
Mark Ursino
  • 31,209
  • 11
  • 51
  • 83
  • wow..that was a very nice function. worked on chrome, safari and firefox. havent tried in internet explorer. someone could do that for me? – ajsie Jan 21 '10 at 05:24
  • 2
    Note that JavaScript allows: `var code = (e.keyCode || e.which);` – Tomas Jul 05 '11 at 09:17
1

A plugin isn't necessary. To detect right clicks, check out this previous question: jquery right click event?

Community
  • 1
  • 1
Justin Johnson
  • 30,978
  • 7
  • 65
  • 89