How to Disabled Right Click in Mouse

If you are looking for How to Disabled Right Click in Mouse then you are at the right place. To do this, kindly copy the source code below to lock the function of the right click in your mouse to avoid the user for copy and paste functions. You can also check the live demo of this simple tutorial, so you can get an idea and you can try this out, let's start coding. In this article, we use message alert box when the user does the right click function in their mouse.

Simple Script

  1. <script language="JavaScript">
  2. var message="You are not authorized to use this!!!";
  3.  
  4. function cLick_All() {if (document.all) {alert(message);return false;}}
  5. function clickDis(e) {if
  6. (document.layers||(document.getElementById&&!document.all)) {
  7. if (e.which==2||e.which==3) {alert(message);return false;}}}
  8. if (document.layers)
  9. {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickDis;}
  10. else{document.onmouseup=clickDis;document.oncontextmenu=cLick_All;}
  11.  
  12. document.oncontextmenu=new Function("return false")
  13. // -->
  14. </script>

Simple Markup

  1. <div style="margin: auto; width: 400px; text-align:center;">
  2.  
  3. <h2 style="color:blue;">
  4. Press the right-click of your mouse
  5. </h2>
  6.  
  7. <a target="_blank" href="https://www.sourcecodester.com/" style="text-decoration: none">
  8. <span style="font-size:larger;">Free Source Code In Sourcecodester.com</span>
  9. </a>
  10. </div>

Output:

Result For the full source code, kindly click the "Download Code" button below. If you are interested in programming, we have an example of programs that may help you even just in small ways. Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment