Erixx
Erixx

Reputation: 125

Right Click brings firefox menu instead of executing jquery code

My issue : if i right click on a TD inside a Datatable, the following code is successfully executed :

$('#mytable tbody tr td').mousedown(function(event){
if(event.which == 3)  //1 for mouseleft button, 2 for middle, 3 for right
{   console.log("Hello");}
});

But, it works only one time !, then, each time i perform a right click again, i get a contextual Firefox menu, instead of my Jquery code.

I tried to add event.preventDefault(); event.stopPropagation(); but it doesn't work. Maybe i put it in the wrong place.

oTable = $('#mytable').DataTable({
fnDrawCallback: function () {
event.stopPropagation();
event.stopImmediatePropagation();
};

Any idea ?

Upvotes: 1

Views: 75

Answers (1)

RRR
RRR

Reputation: 1084

Hi kindly check https://jsfiddle.net/RRR0308/7hq1o31v/ use return false instead of stopPropogation()

Demo Code:

HTML

<div class="div1">

</div>

<div class="msg">

</div>

CSS

.div1{
  height:200px;
  width:200px;
  background:blue;
  margin:50px;
}

jQuery

$(document).ready(function(){
    var i=1;
  $(document).on('contextmenu', '.div1', function(e){

    $('.msg').text('right clicked '+i+' times');
    i++;
    return false;
  });
});

Upvotes: 1

Related Questions