This is going to be a small post. There’s not much to talk about.
HTML has an event called “oncontextmenu”. This event handles the right click event.
So, if you want to disable right click for any field in your page, all you have to do is add “oncontextmenu” inside the particular tag. The example below will make things clear.
Ex. Suppose you want to prevent users from copy pasting something into one of your text boxes. Then you need to write the input tag as follows:
<input type=”text” oncontextmenu=”return false;”>
That’s it!! The context menu does not appear because we are handling the right click event by returning false.
Alternatively, you can disable right click for the whole page as follows:
Just copy paste the following code after the end of your <form> tag.
<script>
document.oncontextmenu = function(){return false}
</script>