For testing purposes, I have disabled the right click function on a web page by adding the following JavaScript snippet code:
document.addEventListener('contextmenu', event => event.preventDefault());
So far, so good.
Now, to re-enable the option using a code method, it is supposed to be enough to just type javascript:void(document.oncontextmenu=null);
in the address bar of your Browser and press Enter. But this method seems not be working anymore. I do not know what is wrong with it and wonder if there is any similar alternative way, except toggling off JavaScript in Chrome?
For testing purposes, I have disabled the right click function on a web page by adding the following JavaScript snippet code:
document.addEventListener('contextmenu', event => event.preventDefault());
So far, so good.
Now, to re-enable the option using a code method, it is supposed to be enough to just type javascript:void(document.oncontextmenu=null);
in the address bar of your Browser and press Enter. But this method seems not be working anymore. I do not know what is wrong with it and wonder if there is any similar alternative way, except toggling off JavaScript in Chrome?
2 Answers
Reset to default 3addEventListener()
method can be removed with removeEventListener()
method only
If you need your code working you need to assign the event with the oncontextmenu
property
I mean that
document.oncontextmenu = (event) => {
event.preventDefault();
}
It will work.
Right-click anywhere on the page (if allowed) and select Inspect or press Ctrl + Shift + I (Cmd + Option + I on Mac) to open the developer tools. Go to the Console tab. Type or paste the following JavaScript mand and press Enter:
document.addEventListener('contextmenu', event => event.stopPropagation(), true);