Failed to identify right click event in Mozilla Firefox.

I am trying to add some kind of behavior for a right click event. Strange, I just can't do event processing.

This is jQuery code:

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

I think the event has been fired, but it cannot be called a “right-click”. A warning message is never displayed. What am I doing wrong? Thanks you!

LE: I can identify the left click event with ev.which === 1. So there are no problems there.

+3
source share
3 answers

clickuse instead mousedown:

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

Using javascript you can try this

document.onmousedown = ListenMouseClick
document.onmouseup = ListenMouseClick

function ListenMouseClick() 
{
if (window.event.button==2 )
    {
        alert('right click')
    }
}
+1
source

"mousedown" "contextmenu"

http://jsfiddle.net/49Ldy/

$('body').on('mousedown','#wrapper',function(ev){
   var evt = ev.which === 3 ? alert('rightClick') : alert('someOtherButton');
});

$('body').on('mousedown','#wrapper',function(ev){
    var evt = ev.which === 3 ? alert('rightClick') : (ev.which === 2 ? alert('auxClick') : alert('someOtherButton'));
});

$('body').on('contextmenu','#wrapper',function(){
    alert('rightClick');
    return false;
});
+1

All Articles