Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trap right-click event?

What is the way to trap a right-click event on a document element? I could not find any event handlers anywhere.

like image 355
KJ Saxena Avatar asked Dec 29 '22 08:12

KJ Saxena


1 Answers

Right-click is special on many browsers, triggering the contextmenu event rather than a click event. Some browsers let you prevent the default behavior, some (Opera, for instance) do not. More here: http://unixpapa.com/js/mouse.html

EDIT: Rereading that page (it'd been a while), it looks like mousedown and mouseup are even more reliable than contextmenu (although all major browsers trigger contextmenu). click, on the other hand, doesn't appear to happen at all, on any significant browser.

like image 70
T.J. Crowder Avatar answered Jan 12 '23 00:01

T.J. Crowder