简体   繁体   English

禁用复制和粘贴

[英]Disable copy and paste

I have used following code to disable copy paste我使用以下代码禁用复制粘贴

onpaste="return false;" oncut="return false;" oncontextmenu="return false;" oncopy="return false;".

This works all fine.这一切正常。 I have install "easy-copy" extension in Google Chrome and can still copy paste.我已经在谷歌浏览器中安装了“easy-copy”扩展程序,仍然可以复制粘贴。 Is there a way to disable copy and paste from extensions as well?有没有办法禁用从扩展中复制和粘贴?

I tried to capture all the events to see what even that extension fire to paste but it doesn't fire any even for pasting.我试图捕获所有事件以查看甚至该扩展程序触发粘贴的内容,但即使粘贴也不会触发任何事件。

For event capturing, I used following code in chrome console:对于事件捕获,我在 chrome 控制台中使用了以下代码:

monitorEvents($0)

In short, how to disable copy paste from browser extension?简而言之,如何禁用浏览器扩展中的复制粘贴? Why do I need this?为什么我需要这个? I have a chat application and some people copy paste to spam.我有一个聊天应用程序,有些人将粘贴复制到垃圾邮件中。

In short, how to disable copy paste from browser extension?简而言之,如何禁用浏览器扩展中的复制粘贴?

I don't think this is possible from the page Javascript, because extensions run at a higher trust level than the webpage.我认为从页面 Javascript 中这是不可能的,因为扩展运行在比网页更高的信任级别。 They can do things that webpages cannot such as change the browser's own behavior.他们可以做网页不能做的事情,比如改变浏览器自己的行为。

In my opinion the best way to handle this is server-side.在我看来,最好的处理方法是服务器端。 Give each post a spam score determined by relevant factors such as frequency of posts from the same user, duplicate content in posts, external links only, downvotes from other users... If a post exceeds a spam score limit, don't show it to other users.给每个帖子一个垃圾邮件分数,由相关因素决定,例如来自同一用户的帖子频率、帖子中的重复内容、仅外部链接、其他用户的反对......如果帖子超过垃圾邮件分数限制,则不要显示它给其他用户。 You could still show it to the poster herself if you want to make it harder for spammers to determine whether their spam is actually getting through.如果您想让垃圾邮件发送者更难确定他们的垃圾邮件是否真的通过了,您仍然可以自己将其展示给海报。

Disabling copy-paste for all users seems heavy handed to me.为所有用户禁用复制粘贴对我来说似乎很棘手。

Hmm just some general thoughts here.嗯,这里只是一些一般性的想法。 Trying to block this kind of operation is never going to fully work because browsers behave differently and ultimately the behaviour can be circumvented no matter what you do.试图阻止这种操作永远不会完全奏效,因为浏览器的行为不同,无论您做什么,最终都可以规避这种行为。

But in terms of making it more awkward why don't you just limit how often they can press the submit button in a given time frame.但就让它变得更尴尬而言,为什么不限制他们在给定时间范围内按下提交按钮的频率。 Or limit the max text size of the textbox.或者限制文本框的最大文本大小。 Better still as per previous comment on the server restrict it this will give you the security that no client side validation will.更好的是根据之前对服务器的评论限制它,这将为您提供没有客户端验证的安全性。 Any client side validation can only hinder attempts but not truly prevent it.任何客户端验证只能阻碍尝试,但不能真正阻止它。

Actually another thing you can do is have an intercepting javascript function that will check for repeated text.实际上,您可以做的另一件事是使用拦截 javascript 函数来检查重复的文本。

Testing it on Chrome在 Chrome 上测试

You can try using您可以尝试使用

 * { user-select: none; -webkit-user-select: none;/*IE,etc*/ -moz-user-select: none; /*Mozzila Firefox*/ }
 <h2>Copy Me if you Can 😆</h2>

On my end this works, try it removing user-select: none;在我看来这有效,请尝试删除user-select: none; and seeing if has any effect.看看有没有效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM