How To Protect Your Web Pages

Protecting your Website Content From Illegal Copy

There might be many reasons you why want to prevent visitors from copying your website content. Server side scripts like and php are always out of the reach of end users, but what about text and images? Sometimes copyright notices don’t seem to be enough and you need to do something more.

So, is there really a way to protect your html pages? The straight answer to this question is no, at least not against the experienced users. But there are a few things you can do to make it harder for the visitors to copy or print the content of your website. Keep in mind that the techniques mentioned here are just a warning to your website visitors rather than a protection for your content. The instant hack to almost all of these tricks is disabling JavaScript. Besides, some browsers, like Opera, do not allow such scripts.

  1. Disabling the Context Menu. Without having a context menu, many people find it very hard to save images or copy text from your website. To disable the right click, simply add this statement to your body tag: oncontextmenu="return false;”
  2. Disabling Copy and Paste. Create a new JavaScript file and type in (or copy and paste!) these lines of codes:
  3. document.onselectstart=new Function('return false');
    function md(e){return false;}
    function dc(){return true;}

    Name the file protect.js and add the following line to the head section of your html page:
    <script type="text/javascript" src="protect.js"></script>

  4. Disabling the CTRL or Command Key. So far you have disabled mouse drag. But users can still copy the text from your website using some key combinations like CTRL + A and CTRL + C. To disable the CTRL key on your web pages, add these lines of codes to the previous JavaScript file:
    function checkkey(e)

    ns4 = (document.layers)? true:false
    ie4 = (document.all)? true:false
    var key;

    if(key == 17)
    alert('Control key is disabled.');
    event.returnValue = false;
    return false;


    You should also add the following code to the <HEAD> tag of your web pages in order to handle key events in supported browsers:
    document.addEventListener("keydown", checkkey, false);
    document.addEventListener("keypress", checkkey, false);
    document.onkeypress =checkkey;
    window.onkeypress =checkkey;
    if (document.layers || (document.getElementById && !document.all)) {

    I have checked the above technique in IE6, IE7 and Firefox. It might not work in other browsers.

  5. Disabling Print. To hide the content of the body tag while printing, add the following line to your external css file: @media print {Body { display:none; }}
  6. Hiding the Source. Users may still copy your content by viewing the page source from their browsers. It’s almost impossible to prevent users from doing so, but there are some complicated ways to hide the actual html code of the page. This is an advanced technique and I don’t want to discuss it here but to give you a hint you can use JavaScript’s document.write() method together with an encryption function to hide some parts of the source from visitors.


Share this article!

Follow us!

Find more helpful articles:



Thanks Mohammad for your comment. That's totally true.

By Amin .