html onclick trigger - How can I capture the right-click event in JavaScript?

1 Answers

I think that you are looking for something like this:

   function rightclick() {
    var rightclick;
    var e = window.event;
    if (e.which) rightclick = (e.which == 3);
    else if (e.button) rightclick = (e.button == 2);
    alert(rightclick); // true or false, you can trap right click here by if comparison


And then use the onmousedown even with the function rightclick() (if you want to use it globally on whole page you can do this <body onmousedown=rightclick(); >

menu jquery oncontextmenu

This question already has an answer here:

I want to block the standard context menus, and handle the right-click event manually.

How is this done?