Sometimes, we want to re-enable right click to let us inspect HTML elements in Chrome with JavaScript.
In this article, we’ll look at how to re-enable right click to let us inspect HTML elements in Chrome with JavaScript.
How to re-enable right click to let us inspect HTML elements in Chrome with JavaScript?
To re-enable right click to let us inspect HTML elements in Chrome with JavaScript, we can set the oncontextmenu of elements in our page to null.
For instance, we can set the right click handler of the window to null by running
window.oncontextmenu = null;
in the console.
We can also run
const elements = document.getElementsByTagName("*");
for (const element of elements) {
element.oncontextmenu = null;
}
to select all elements on the page with getElementByTagName.
Then we loop through each element in elements and set its oncontextmenu property to null.
Conclusion
To re-enable right click to let us inspect HTML elements in Chrome with JavaScript, we can set the oncontextmenu of elements in our page to null.