After hacking to pieces Kangax's right click menu i discovered it is not the 
right thing for me....

however i cannot see why the following code does not work seeing as i pass 
event to the anonymous function/......

$('foo').observe('click', function(event) {
// alert(event); // alerted as a mouse Event as expected
event.stop(); // doesnt stop the event
        console.log('Stopped Context Menu ' + event.isRightClick()); // only 
logs left clicks
        event.stop(); // doesnt stop the event

according to your Pastie link TJ, this code should work as its just a 
simpler version of it (in essence logging to console true or false of a left 
or right click.....) it seems FF 3.010 (last update was thursday iirc) it 
does not work on.

Am i using event.stop() wrong ? because Event.stop(event); does not work 

Thanks in advance


----- 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