Search code examples
javascriptjquerykeyboard

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.

Solution

  • Selecting text, copy, the right click can be disabled on a web page easily using jQuery. Below is the simple jQuery code snippet which can do this task easily:

    <script type="text/javascript">
    // Disable right click on web page
    $("html").on("contextmenu",function(e){
        return false;
    });
    // Disable cut, copy and paste on web page
    $('html').bind('cut copy paste', function (e) {
         e.preventDefault();
    });
    </script>
    

    Source: Disable right click, copy, cut on web page using jQuery