How to prevent default right-clicking on a canvas containing an image

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

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

I would expect this code to follow my steps and prevent the default browser behavior. The former is executed, but the latter, namely: the prevention of default behavior does not occur. The event is passing. I wonder how I could prevent this menu from showing, which you can see in the image by right-clicking:

enter image description here

+5
source share
1 answer

You can use contextmenu :

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

All Articles