Disabling right click context menu on a HTML Canvas?

You can use this:

$('img').bind('contextmenu', function(e){
    return false;

See this working example!

With the lastest jQuery:

$('body').on('contextmenu', 'img', function(e){ return false; });

Note: You should use something narrower than body if possible!

Or without jQuery, applying on canvas:

canvas.oncontextmenu = function(e) { e.preventDefault(); e.stopPropagation(); }


Updated the Fiddle Example to show the contextmenu being limited to the canvas and not the image.


$('body').on('contextmenu', '#myCanvas', function(e){ return false; });


<canvas id="myCanvas" width="200" height="100">
  Your browser does not support the canvas element.

<img src="http://db.tt/oM60W6cH" alt="bubu">

Leave a Comment