Prevent Copy and Paste Using Javascript

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3jQhvjBbLIFBXDWM1gOiBGtkCXAErq8KqxjzE5k3d0coKRGaegeICNUMc46E-PF5sE7Z1gv3ynLb6pAHL_OEEwBNUjfYlgMnBFb3uye7rmyTelcRWVhbezsn-kvWY3-MihB2t2YE8Oq0/s200/Do+not+copy+paste.gif


Copy and Paste prevention on your web page sometimes is necessary because it's quite annoying when other user just copy your articles or contents without your permission.

We could prevent it using javascript with this code :

 <script language='javascript'>  
   function disableselect(e){  
       return false;  
   }  
   function reEnable(){  
       return true;  
   }  
   document.onselectstart=new Function ('return false');  
   if (window.sidebar){  
       document.onmousedown=disableselect  
       document.onClick=reEnable  
   }  
 </script>  

Above code would prevent user to highlight the text or content which means left click is disabled, so the user can not select the text or content to be copied.

Or you could use this code below to disable right click and give the user with alert or warning :

 <script language=JavaScript>  
 var message="Right Click is Disabled!";  
 function clickIE4(){  
 if (event.button==2){  
 alert(message);  
 return false;  
 }  
 }  
 function clickNS4(e){  
 if (document.layers||document.getElementById&&!document.all){  
 if (e.which==2||e.which==3){  
 alert(message);  
 return false;  
 }  
 }  
 }  
 if (document.layers){  
 document.captureEvents(Event.MOUSEDOWN);  
 document.onmousedown=clickNS4;  
 }  
 else if (document.all&&!document.getElementById){  
 document.onmousedown=clickIE4;  
 }  
 document.oncontextmenu=new Function("alert(message);return false")  
 </script>  

Just copy above code between your <head> </head> tag and let's magic happen.

Comments