2

I'm facing a weird issue in firefox . stopPropagation() not working for right click in firefox in my code but if I use an alert or breakpoint before the code it will work. it working smoothly in ie,safari,chrome,opera my code is given below

jquery

$("#div-login").click(function (e) {
    e.stopPropagation();
});

then this

$("#div-login").mousedown(function (e) {
   e.stopPropagation();
});

and this too

    $("#div-login").click(function (e) {
     if(e.button ===2)
       e.stopPropagation();
    });

markup

<div="div-login">
  <fieldset>
         ---markup----
                        </fieldset>
</div>

but none of the above code is working for right click in firefox but working without a problem for left-click

I couldn't find out the problem please help....

Optimus
  • 2,130
  • 8
  • 36
  • 67

3 Answers3

1

try contextmenu, like:

$('#div-login').on("contextmenu",function(e){
   e.stopPropagation();
}); 

or

$('#div-login').on("click",function(e){
   if(e.which == 3) {  //right click
       e.stopPropagation();
   }
}); 
Sudhir Bastakoti
  • 97,363
  • 15
  • 155
  • 158
0

I think what you need is the contextmenu event

$("#div-login").on('contextmenu',function (e) {
    e.stopPropagation();
});

Demo: Fiddle

Also see: Can't use jquery's click event handler to detect right click

Community
  • 1
  • 1
Arun P Johny
  • 376,738
  • 64
  • 519
  • 520
0

HTML

<div id="box">
    <div id="div-login"></div>
</div>

jQuery

$('#div-login').on('mousedown', function (e) {
    if(e.button == 2 ) e.stopPropagation();
});

$('#box').on('mousedown', function () {
    alert('Right');
});

Works fine for me in FF and Chrome

DEMO with stopPropagation()

DEMO without stopPropagation()

alexP
  • 3,559
  • 5
  • 23
  • 34