thanks TJ, i noticed kangax coded a really nice right click menu.. now 
normally i would use somehting like this but i need the menu to be filled 
with an ajax request response .. perhaps i will hack his to peices and see 
what i can do !!!!!!!

----- Original Message ----- 
From: "T.J. Crowder" <>
To: "Prototype &" <>
Sent: Tuesday, May 05, 2009 11:14 AM
Subject: [Proto-Scripty] Re: Catching right click


Right-click is a bit of a pain. :-)  Mostly, browsers fire the
'contextmenu' event instead of 'click', but not all browsers do and
not all browsers allow you to replace (e.g., prevent) the default
action of bringing up the context menu.  (Opera is a particular
problem; I think recent versions have a config setting allowing the
user to allow you to do it, but the default is off, so...)  This page
[1] on quirksmode gives you an idea of support across browsers.

Browsers seem quite reliable about firing 'mousedown' and 'mouseup' on
right-clicks (even Opera, but don't get excited, stopping the default
on mousedown or mouseup doesn't stop the context menu).  You can use
Event#isRightClick to see if it's a right-click (note that !
Event#isLeftClick doesn't mean it's a right-click, it could be a
middle-click).  Apparently Event#isRightClick and Event#isMiddleClick
are missing from the API docs, but they're in Prototype and
1.6.1 RC2 (at least).  Really those methods should be isLeftButton,
isRightButton, and isMiddleButton as they work regardless of whether
it's a "click", but never mind.

Here's a quick-and-dirty test page for mouse events you can play with.


T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On May 5, 9:28 am, Jeztah <> wrote:
> I need to catch the right click of a mouse in an element...
> Unfortunately i am at a bit of a halt ....
> $('myDiv').observe('click', function(event) {
> if(!Event.isLeftClick(event)) {
> alert('Right Click'); // doesnt work in firefox
> Event.stop(event); // doesnt work in firefox
> } else {
> alert('Left Click');
> }});
> can anyone point me in the right direction ?
> Ta
> Alex

You received this message because you are subscribed to the Google Groups 
"Prototype &" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to