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?
- @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 fordom.event.clipboardevents.enabled
, and set it tofalse
. – Lambart Commented Jun 18, 2015 at 21:36
4 Answers
Reset to default 3You 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
版权声明:本文标题:javascript - Cross-browser method to prevent all methods of text copying from a textarea? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745319732a2653322.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论