oncontextmenu and preventDefault for right clicks in Firefox

C

Charlie

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
 
J

john.svensk

Charlie said:
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/DOM:event.preventDefault
http://developer.mozilla.org/en/docs/DOM:event.stopPropagation

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top