Prevent mobile context menu for chessboard.js

55 Views Asked by At

Using chessboardjs.com. Pressing a piece brings up the context menu. enter image description here

Need to prevent this context menu appearing.

I tried this code:

$('.square-55d63').contextmenu(function(e){
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return false;
});

It does not work.

Any help would be appreciated.

1

There are 1 best solutions below

0
Mahesh Thorat On BEST ANSWER

You can use JS / jQuery only you the thing is to bind it to the document/window. Or wrap that element in your custom element. So you can block contextmenu

Jquery example

$(window).contextmenu(function(e){
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

JS example

document.oncontextmenu = function(e){
 var evt = new Object({keyCode:93});
 stopEvent(e);
}
function stopEvent(event){
 if(event.preventDefault != undefined)
  event.preventDefault();
 if(event.stopPropagation != undefined)
  event.stopPropagation();
}