Is right click an javascript event? If so, how do I use it?
Yes - it is!
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
}
No, but you can detect what mouse button was used in the "onmousedown" event... and from there determine if it was a "right-click".
Kinda, check this out: http://www.rgagnon.com/jsdetails/js-0061.html
Yes, its a javascript mousedown event. There is a jQuery plugin too to do it
Yes, it's called MouseEvent. See http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-MouseEvent for the spec.
For an example, see e.g. http://unixpapa.com/js/mouse.html .
As others have mentioned, the right mouse button can be detected through the usual mouse events (mousedown, mouseup, click). However, if you're looking for a firing event when the right-click menu is brought up, you're looking in the wrong place. The right-click/context menu is also accessible via the keyboard (shift+F10 or context menu key on Windows). In this situation, the event that you're looking for is oncontextmenu:
window.oncontextmenu = function ()
{
showCustomMenu();
return false; // cancel default menu
}
As for the mouse events themselves, browsers set a property to the event object that is accessible from the event handling function:
document.body.onclick = function (e) {
var isRightMB;
e = e || window.event;
if ("which" in e) // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
isRightMB = e.which == 3;
else if ("button" in e) // IE, Opera
isRightMB = e.button == 2;
alert("Right mouse button " + (isRightMB ? "was not " : "") + "clicked!");
}
have a look at the following jquery code:
$("#myId").mousedown(function(ev){
if(ev.which == 3)
{
alert("Right mouse button clicked on element with id myId");
}
});
The value of which will be 1 for the left button, 2 for the middle button, or 3 for the right button.