Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent default right click on canvas containing image

I have a canvas and I display an image inside it. I have attached a jquery event to it, like this:

$("#mycanvas").mousedown(function(e) {
    //Do something
    e.preventDefault();
    e.stopPropagation();
});

I would expect this code to do my operations and to prevent default browser behavior. The former is fulfilled, however, the latter, namely, default behavior prevention does not happen. The event runs though. I wonder how could I prevent showing that menu you can see on the image upon right-click:

enter image description here

like image 673
Lajos Arpad Avatar asked Jul 28 '16 08:07

Lajos Arpad


1 Answers

You can use contextmenu:

$("#mycanvas").contextmenu(function(e) {
    //Do something
    e.preventDefault();
    e.stopPropagation();
});
like image 98
Bhojendra Rauniyar Avatar answered Nov 11 '22 13:11

Bhojendra Rauniyar