Lajos Arpad
Lajos Arpad

Reputation: 76892

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

Upvotes: 9

Views: 4190

Answers (1)

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85573

You can use contextmenu:

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

Upvotes: 13

Related Questions