跨浏览器方法,以防止从textarea的所有文本复制方法? [英] Cross-browser method to prevent all methods of text copying from a textarea?

查看:93
本文介绍了跨浏览器方法,以防止从textarea的所有文本复制方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在线打字软件。在打字软件中,一切进展顺利,但我遇到了不诚实用户的问题,他们可能会将文本输入到textarea中,复制它,然后重新加载页面(因此重置计时器)并直接粘贴它。因此,我在考虑使用类似 evt.preventDefault(); 的内容,当javascript检测到按下ctrl / cmd按钮以及时C 键。但后来我意识到用户总是可以到菜单栏按编辑 - >复制。所以我想知道,是否有一种跨浏览器方法来禁用这两种复制方法?

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?

推荐答案

您可以尝试使用以下jQuery代码:

You can try to use the following jQuery code:

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

这篇关于跨浏览器方法,以防止从textarea的所有文本复制方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆