469,570 Members | 1,718 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,570 developers. It's quick & easy.

oncontextmenu and preventDefault for right clicks in Firefox

I want to detect and act on right button clicks in Firefox. The problem
was I kept getting the context menu pop up on right button clicks, even
when I called event.preventDefault(). I had assumed that this would
prevent the context menu which seems to be the default action. Why does
this not prevent the context menu from popping up?

Someone mentioned using the "contextmenu" event which I had assumed was
IE-only. I could not find it in the Mozilla documentation but it seems
to work in Firefox. When I used event.preventDefault() in the
conextmenu event handler it took care of the problem.

One other strange thing. The mousedown event from a right mouse click
has button=2 as expected but the corresponding mouseup event has
button=0. Why is that?

--Charlie Crowley

Dec 2 '06 #1
1 8817
Charlie wrote:
I want to detect and act on right button clicks in Firefox. The problem
was I kept getting the context menu pop up on right button clicks, even
when I called event.preventDefault(). I had assumed that this would
prevent the context menu which seems to be the default action. Why does
this not prevent the context menu from popping up?
Try these:
http://developer.mozilla.org/en/docs...preventDefault
http://developer.mozilla.org/en/docs...topPropagation

preventDefault() doesn't stop the event from bubbling further up the
tree...
stopPropagation() hides the event from other handlers further up the
DOM tree.

/John

Jan 23 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by johkar | last post: by
3 posts views Thread by Michael Powe | last post: by
44 posts views Thread by Viken Karaguesian | last post: by
4 posts views Thread by Doug Lerner | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.