Javascript - Event properties:

Right click

Fortunately you most often want to know if the right button has been clicked. Since W3C and Microsoft happen to agree on this one and give button a value of 2, you can still detect a right click.

function doSomething(e) {
var rightclick;
if (!e) var e = window.event;
if (e.which) rightclick = (e.which == 3);
else if (e.button) rightclick = (e.button == 2);
alert('Rightclick: ' rightclick); // true or false
}


Please note that, although Macs have only one mouse button, Mozilla gives a Ctrlโ€“Click a button value of 2, since Ctrlโ€“Click also brings up the context menu. iCab doesnโ€™t yet support mouse button properties at all and you cannot yet detect a rightโ€“click in Opera.

See the Image protection script for a practical example of rightโ€“click detection.