Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failing to identify right click event in Mozilla Firefox

I'm trying to add some behavior for the right click event. Weirdly I simply cannot make the event handling work.

This is the jQuery code:

$('body').on('click', '#wrapper', null, function(ev){
    if (ev.which === 2 || ev.which === 3){
        alert("Here!");
    }
});

I think that the event is fired but it cannot be identified as a "rightclick". The alert message is never shown. What am I doing wrong? Thanks you!

LE: I am able to identify the left click event with ev.which === 1. So there is no problem there.

like image 833
TGM Avatar asked Jan 30 '26 20:01

TGM


1 Answers

instead of click use mousedown:

$('body').on('mousedown', '#wrapper', null, function(ev){
    if (ev.which === 2 || ev.which === 3){
        alert("Here!");
    }
});​
like image 188
mgraph Avatar answered Feb 02 '26 10:02

mgraph