admin管理员组

文章数量:1420966

I am working on an online typing software. In the typing software, all is going well but I have the problem of dishonest users who might possibly type the text into the textarea, copy it, then reload the page (therefore resetting the timer) and pasting it in straightaway. So I was thinking along the lines of using something like evt.preventDefault(); when javascript detects the pressing of the ctrl / cmd button along with the C key. But then I realized that the user could always go up to the menu bar to press Edit -> Copy. So I was wondering, is there a cross-browser method to disable both methods of copying?

I am working on an online typing software. In the typing software, all is going well but I have the problem of dishonest users who might possibly type the text into the textarea, copy it, then reload the page (therefore resetting the timer) and pasting it in straightaway. So I was thinking along the lines of using something like evt.preventDefault(); when javascript detects the pressing of the ctrl / cmd button along with the C key. But then I realized that the user could always go up to the menu bar to press Edit -> Copy. So I was wondering, is there a cross-browser method to disable both methods of copying?

Share Improve this question edited Aug 30, 2012 at 8:33 Zerium asked Apr 9, 2012 at 8:52 ZeriumZerium 17.4k32 gold badges118 silver badges187 bronze badges 3
  • @think123: i have a solution for your previous deleted question (how e my php mysql code only displays one td) – GoSmash Commented Apr 12, 2012 at 10:42
  • oh that one is solved (I think). Sorry about that. – Zerium Commented Jun 13, 2012 at 8:43
  • Just remember that nothing you do will prevent people from blocking clipboard events in their browser. For instance, in Firefox we just go to about:config and search for dom.event.clipboardevents.enabled, and set it to false. – Lambart Commented Jun 18, 2015 at 21:36
Add a ment  | 

4 Answers 4

Reset to default 3

You can try to use the following jQuery code:

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

You maybe 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 the content by other means, as suggested in your question.

You can block some events, but preventing such user behaviour is not possible. User can always copy text from DOM node via browser console.

Bind the event handlers and prevent the clipboard function like such:

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

本文标签: javascriptCrossbrowser method to prevent all methods of text copying from a textareaStack Overflow