Disable Mouse Right Click Cut Copy Paste Using Jquery

Disable Mouse Right Click Cut Copy Paste Using Jquery | Tech Trick Corner

Do you want to prevent visitors from copying your web page content?
In this short jQuery article, we’ll show you how to stop content theft from your website using jQuery. For stopping the content copy of your website you can do two things, one is to disable the mouse right click and second is to disable the cut (CTRL+X), copy (CTRL+C) and paste (CTRL+V). Using of jQuery, you can easily disable mouse right click and disable cut, copy and paste from web content.


Step 01: At first include the jQuery library.

 <script src="jquery.min.js"></script>  

Step 02: Disable Mouse Right Click
Disable mouse right click will prevent visitors from choosing the cut, copy and paste options. If you want to disable right mouse click for a particular section of a web page, then you can use a selector (#id, .class, etc.) otherwise use body selector for the full page. The following JavaScript code is used to disable mouse right click.

 <script type="text/javascript">  
 $(document).ready(function () {  
   //Disable full page  
   $("body").on("contextmenu",function(e){  
     return false;  
   });  
   //Disable part of page  
   $("#id").on("contextmenu",function(e){  
     return false;  
   });  
 });  
 </script>  

Step 03: Disable Cut Copy & Paste
The following JavaScript code will disable cut, copy and paste from your web page or a part of your web page.

 <script type="text/javascript">  
 $(document).ready(function () {  
   //Disable full page  
   $('body').bind('cut copy paste', function (e) {  
     e.preventDefault();  
   });  
   //Disable part of page  
   $('#id').bind('cut copy paste', function (e) {  
     e.preventDefault();  
   });  
 });  
 </script>  

Step 04: Disable Mouse Right Click, Cut, Copy & Paste
Full JavaScript code for disabling mouse right click and disable cut (CTRL+X), copy (CTRL+C) and paste (CTRL+V) from the web page.

 <script type="text/javascript">  
 $(document).ready(function () {  
   //Disable cut copy paste  
   $('body').bind('cut copy paste', function (e) {  
     e.preventDefault();  
   });  
   //Disable mouse right click  
   $("body").on("contextmenu",function(e){  
     return false;  
   });  
 });  
 </script>  

And  Mouse Right Click Cut Copy Paste will be disabled.
SHARE

Tech Tricks

  • Image
  • Image
  • Image
  • Image
  • Image

1 comments:

  1. If you are just now moving from an old-style ball mouse and looking to get a wireless mouse as a replacement, you are in for a big surprise. Today's mice are far more accurate than they have ever been before, and they don't have a ball to get clogged and clean out every once in a while. Bluetooth mouse

    ReplyDelete