javascript - Cross-browser method to prevent all methods of text copying from a textarea? - Stack Overflow

I am working on an online typing software. In the typing software, all is going well but I have the pro

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();
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745319733a4622388.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信