Reputation: 43
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. 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:
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.
Upvotes: 0
Views: 3621
Reputation: 11
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;
and seeing if has any effect.
Upvotes: 1
Reputation: 40886
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. 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.
Upvotes: 1
Reputation:
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.
Upvotes: 0