How can I capture the right-click event in JavaScript?

Use the oncontextmenu event. Here’s an example: And using event listeners (credit to rampion from a comment in 2011): Don’t forget to return false, otherwise the standard context menu will still pop up. If you are going to use a function you’ve written rather than javascript:alert(“Success!”), remember to return false in BOTH the function AND the oncontextmenu attribute.

the getSource() and getActionCommand()

Assuming you are talking about the ActionEvent class, then there is a big difference between the two methods. getActionCommand() gives you a String representing the action command. The value is component specific; for a JButton you have the option to set the value with setActionCommand(String command) but for a JTextField if you don’t set this, … Read more

jQuery preventDefault() not triggered

Update And there’s your problem – you do have to click event handlers for some a elements. In this case, the order in which you attach the handlers matters since they’ll be fired in that order. Here’s a working fiddle that shows the behaviour you want. This should be your code: Note that the order of attaching the handlers has been … Read more

How is JavaScript .on() method defined?

on method registers a handler, which is callback function with specific signature. Once an event is triggered, a handler is called. It receives necessary data as function parameters (commonly event object). jQuery and Node event emitter aren’t related in any way, they both have on method because it’s a conventional way for a method that adds event handlers. A naive … Read more