How To Disable Right Click, Cut, Copy and Paste Using Javascript

How To Disable Right Click, Cut, Copy and Paste Using Javascript

Hi there!

When it comes to internet, It is not easy to protect your content. If you put unique content on your blogs, you don't need to surprise if it appears on some other blogs.

Hell lot of copy cats out there. They are noobs They are ready to steal your content as soon as you put it there. 

If you want to prevent your visitors from copying your content, you can do this by disabling right click, CNTRL+C, CNTRL+V, CNTRL+X in your pages.

Although it may not work 100% but it helps a bit.

Let's start!

I believe you have little bit knowledge in basic Web Development Technologies including HTML,JavaScript and JQuery.

In this tutorial we will be using javascript library i..e JQuery.

First of all include jquery library in your website. Copy the below code and paste it inside the <head> section your website.


[ <script src="jquery-3.3.1.min.js"></script> ]

1. Disable Mouse Right Click 

If you want disable right clicking, include below code in your in your webpage.
If you want to disable right click on certain pages, change that red coloured part with your own #id or .class name given to that page.
<script type="text/javascript">
$(document).ready(function () { $("body").on("contextmenu",function(e){ return false; }); }); </script>

 ]

2. Disable CUT, COPY, PASTE 

If you want disable cut, copy, paste, include below code in your in your webpage.
If you want to disable on certain pages, change that red coloured part with your own #id or .class name given to that page.

<script type="text/javascript">$(document).ready(function () {

$('body').bind('cut copy paste', function (e) {
e.preventDefault();
});
});
</script>
 ]

Full Code Together

<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>
If you have any doubt, Please reach us through comment section or from contact page.

Post a Comment

0 Comments