Skip to main content
Script to protect text from being copied

Here is the right-click ban script:

<script type="text/javascript">

var message="The right mouse button is disabled!";
function click(e) {
   if (document.all) {	// IE
      if (event.button == 2) {	// To deactivate the left-hand button, set the number 1
          alert(message);	// to deactivate the middle button, set the number 1
          return false;}
      }
   if (document.layers) { // NC
      if (e.which == 3) {
          alert(message);
          return false;}
      }
}
if (document.layers)
   {document.captureEvents(Event.MOUSEDOWN);}
document.onmousedown=click;
document.oncontextmenu=function(e){return false};

</script>

I propose to use an alternative option, which won't inconvenience ordinary users and might even be good for SEO. The Javascript below, unlike the previous one, doesn't forbid copying the text, but inserts a hidden link to the original source.

Of course, an experienced copy-pasteer is likely to notice it in the code. But some of such links can stay on external sites and bring backlinks to your site. Here's the script itself, which allows you to insert a hidden link to the original site:

  <script type="text/javascript">
//<![CDATA[
function addLink() {
    var body_element = document.getElementsByTagName('body')[0];
    var selection = window.getSelection();

     var pagelink = "<p>Source: <a href='"+document.location.href+"'>"+document.location.href+"</a></p>";

    var copytext = selection + pagelink;
    var newdiv = document.createElement('div');
    newdiv.style.position = 'absolute';
    newdiv.style.left = '-99999px';
    body_element.appendChild(newdiv);
    newdiv.innerHTML = copytext;
    selection.selectAllChildren(newdiv);
    window.setTimeout( function() {
        body_element.removeChild(newdiv);
    }, 0);
}
document.oncopy = addLink;
//]]>
</script>
  

Insert this Javascript into your website template file (each CMS has its own file) before the closing </body> tag. By default this script will insert anchorless link like:

Source: http//website address/which page address the text is copied from

I advise you not to change this view, because unanchored link looks more natural and risks to get filter from search engines are minimized, but if you want to change it, then "saw" this part of code:

 var pagelink = "<p>Source: <a href='"+document.location.href+"'>"+document.location.href+"</a></p>";

where the second "+document.location.href+" between the <a></a> tags can be replaced with the anchor you want.