Cross browser method to prevent all methods of copying text from text field?

I am working on an online text input software. Everything is going fine in the input software, but I have a problem of dishonest users who can enter text in a text box, copy it, and then reload the page (so reset the timer) and paste it right away. So I was thinking of using something like evt.preventDefault(); when javascript detects a press of the ctrl / cmd button along with the C key. But then I realized that the user can always go to the menu bar to click Edit -> Copy . So I was wondering if there is a cross browser method to disable both copy methods?

+7
source share
4 answers

You can try using the following jQuery code:

 $('input[type=text],textarea').bind('copy paste cut drag drop', function (e) { e.preventDefault(); }); 
+4
source

Perhaps you could do something like:

 var txtArea = document.getElementById("YourTextAreaId"); txtArea.oncopy = function() { return false; } txtArea.onpaste = function() { return false; } txtArea.oncut = function() { return false; } 

But even then, the user can copy content in other ways, as suggested in your question.

+2
source

You can block some events, but you cannot prevent this user behavior. The user can always copy text from the DOM node through the browser console.

+1
source

Bind event handlers and prevent such a clipboard function:

 $('textarea').on('copy paste cut drag drop', function (e) { e.preventDefault(); }); 
0
source

All Articles