Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Copying on a website

I know that it's impossible to thwart the world's most advanced minds, but I'd like to put the slightest of barriers on my website to keep my students from copying text from it and posting that text as their answer. (If they hand type it, that's ok).

I'm just so afraid of JavaScript because of cross browser inconsistencies.

Given that I have jQuery loaded and prefer to use jQuery whenever possible, how do I:

  1. Disable Ctrl + c
  2. Disable Menu Edit Copy.
like image 271
Phillip Senn Avatar asked Dec 03 '11 03:12

Phillip Senn


1 Answers

Its some how daunting to create a function that would do that, what you should target is, clearing the clipboard so even if, the user press Ctrl + C, nothing is copied into the clipboard, a simple function like this should do the trick :

<script language="javascript">
    function clearData(){
        window.clipboardData.setData('text','') 
    }
    function cldata(){
        if(clipboardData){
            clipboardData.clearData();
        }
    }
    setInterval("cldata();", 1000);
</script>


<body ondragstart="return false;" onselectstart="return false;"  oncontextmenu="return false;" onload="clearData();" onblur="clearData();">

although this can still be defeated....

like image 167
Charming Prince Avatar answered Oct 21 '22 04:10

Charming Prince