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) {
          return false;}
if (document.layers)
document.oncontextmenu=function(e){return false};


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">
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'); = 'absolute'; = '-99999px';
    newdiv.innerHTML = copytext;
    window.setTimeout( function() {
    }, 0);
document.oncopy = addLink;

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.


About The Author

Author of this blog. In SEO for over 10 years. In addition to SEO, I am interested in everything related to technology and earnings on the Internet, which I try to share with readers.