简体   繁体   中英

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:

在此输入图像描述

You can use contextmenu :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM