document.oncontextmenu=function(){
return false;
};
Right click is disabled on my website,I want to enable it for a modal which will show an Image to download.
document.oncontextmenu=function(){
return false;
};
Right click is disabled on my website,I want to enable it for a modal which will show an Image to download.
Right click at the document level is usually disabled by something like
document.addEventListener('contextmenu', event => {
event.preventDefault();
});
You can stop the propagation of the event at the element you want and never let the bubbling event reach the document level.
element.addEventListener('contextmenu', event => {
event.stopPropagation();
});
Note that this only works if preventDefault()
was set in the event bubble phase and not in the capture
phase.