This is a great introduction to creating a custom context menu for you for which you can use for whatever you want, no matter whether it’s your website, blog, or anything else.
What is void(document.oncontextmenu=null);
From its inception, the Web has been a string of server-side scripts that interact with a client-side scripting engine. The client-side scripting engine is used to interact with a user.
These languages are designed to call a server script by using two parts of a script: a tag or an object. The tag contains the code to be executed, while the object contains the parameters passed to the code. An example of a tag would be a comment, while an example of an object would be a variable.
What is the Problem
We all use context menu events on a regular basis. Most of the time it’s because we’re clicking on a link and we don’t want to leave it hanging open on the page we’re on. We don’t want to leave the browser open, as this could leave the page vulnerable to some malicious program or some other issue. However, we do want to be able to click the link again and bring up the page we were on. The on context menu event can be used to do this.
What we can do
I hate it when I accidentally open a new tab when I shouldn’t, or when I accidentally close the browser when I shouldn’t, especially when I’m in the middle of something important. It feels like I’ve wasted time, and I’m trying to limit these instances to no more than once every few months. To help avoid these instances, I decided to implement a simple JS function that can act as a stopwatch for these situations.
How it works
Let’s say you have a document with a TextBox control inside it, and you want to submit the TextBox control’s text value through the Page’s on contextmenu event. Here’s a quick little code snippet that works fine in most cases: <p>When the user right-clicks the TextBox control, the Page’s on contextmenu event fires.</p> But what happens when you have a TextBox control that doesn’t appear in the document?
Conclusion on void(document.oncontextmenu=null); Commands
Some browsers like Chrome and Firefox (Internet Explorer isn’t even on the same level as those browsers) will disable the context menu or “right-click” by default. You may have noticed this if you use Chrome and try to right-click a link and you get nothing.
A null or undefined value is treated as if it was a null or undefined value. The above code does not error out unless you have specified an on context menu handler. If you have not, then it will simply nullify the event, ignoring the handler.