As a website visitor you have seen that many sites restrict to copy web page content. In this tutorial we will discuss how to restrict your webpage content being copy.
Basically there two option to restrict from content copy of your website. But before proceed we must know this would not work when JavaScript is disabled in browser.
So this method could not considered really good to protect content. But we must know about possibility too.
So, let us see below.
I) Disable the command like cut, copy and paste
II) Disable the mouse right click
Both options can be achieved or done using jQuery to stop content copy of site. Let us see the snippet how disable right click or cut, copy and paste command to restrict from content copy using jQuery.
Table of Contents
How to disable Copy, Paste, Cut and Right Click using jQuery
We will discuss each option one by one.
I) Disable the shortcut keys like cut ,copy and paste
We can disable cut(CTRL+X), Copy (CTRL+C) and Paste (CTRL+V) command using jQuery. Let us discuss snippet to disable command. Disable cut, copy and paste on body , #id and .class selector.
<script> $(document).ready(function(){ //disable cut,copy and paste on full webpage $('body').bind('cut copy paste',function(e){ e.preventDefault(); }); //disable cut,copy and paste on section of webpage $('#spec').bind('cut copy paste',function(e){ e.preventDefault(); }); }); </script>
II) Disable Mouse Right Click
When we disable mouse right click a visitor will not get an option cut, copy and paste content from site using mouse right click.
If we want to disable mouse right click on complete webpage then we use body as selector otherwise we can set on different section of webpage too using #id, .class selector.
e.g:
<script> $(document).ready(function(){ //disable mouse right click on full webpage $('body').on('contextmenu',function(){ return false; }); //disable mouse right click on section of webpage $('#spec').on('contextmenu',function(){ return false; }); }); </script>
Alternate : to disbale mouse right click on complete webpage
<body OnContextMenu= "return false">
Above snippet is to disable mouse right click, cut , copy and paste using jQuery. This snippet will work when browser is enabled for JavaScript.
If you liked this article 🙂 please share with your friends and colleagues 🙂 . If you have any query feel free to write in comment box.