How to Stop People from Copying Your Content (and Make Them Paste Nonsense Instead!)
So, you know how sometimes people try to copy your blog posts or work and use it as their own? It's frustrating, right? Well, don't worry! I’ve got a cool little trick to help you stop that from happening.
This is not the first time I am posting something like this. Here is a simple Anti-copy script and a Disable right-click to prevent copy code I previously shared.
And guess what? Today's code is more interesting to prevent copying on a site as it even replaces the copied text with a custom message content or some random nonsense! 😆
In this post, I’m going to show you two simple ways to either completely block copying or give them a surprise instead. Let’s dive in.
1. Block Copying Completely with No Copy Message Replacement
If you just don’t want anyone copying anything from your page, you can use a short piece of code that stops the copying action. Here’s how it works:
<script type='text/javascript'>
document.addEventListener("copy", function(evt){
evt.clipboardData.setData("text/plain", "Copying is not allowed on this webpage");
evt.preventDefault();
}, false);
</script>
This little script will do the magic. When someone tries to copy anything from your page, it replaces whatever they copied with the message: "Copying is not allowed on this webpage." It’s like saying “No copying!” in a friendly way. 😄
To use this, just add the code inside your HTML or blog post. If you're using Blogger, you can add it in your template or inside a specific post using the HTML editor.
2. Make Them Copy Random Nonsense!
Now, if you want to be a bit sneaky (and funny 😜), you can replace the copied content with some random nonsense. Yes, you heard that right! Instead of letting them copy your hard work, they’ll get a bunch of random letters, numbers, and symbols.
Here’s the code for that:
<script type="text/javascript">
document.addEventListener("copy", function(evt) {
// Generate a random string of nonsense character
const randomString = generateRandomString(20); // Change the length as needed
evt.clipboardData.setData("text/plain", randomString);
evt.preventDefault();
}, false);
function generateRandomString(length) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()';
let result = '';
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
}
</script>
What happens here is simple. When someone tries to copy, the script generates a random string, like this: Xg7jH#y9Mkp!Q!2
and puts that in their clipboard instead of the content. Imagine the surprise when they try to paste it somewhere! 😂
You can also adjust the length of the nonsense string. I set it to 20, but you can make it shorter or longer depending on how much nonsense you want to give them.
How to Use Both Codes
- For blocking copying: Just add the first code to your page, and no one can copy anything.
- For replacing with random nonsense: Use the second one, and surprise anyone who tries to copy!
You can add these scripts to any site under the <head>
section or before the close of </body> tag
Hehehe 😅
Blocking copying or replacing content with random nonsense might seem like small things, but it can be a fun way to protect your work and keep things light-hearted. Plus, no one will be stealing your content without a little surprise!
Mxm 🤔 this is fool proof but smarties can get a way around it.
Try this out. 😊
And you may also add this force enable javascript code to your site to prevent some smarties from working a way to copy by disabling javascript on their browser
Stay creative, and keep blogging! 🌸