How to Add JavaScript to Disable Text Selection, Copy-Paste, and More

If you want to safeguard your website's content, you can take it a step further by not only disabling text selection but also blocking copy-paste actions, keyboard shortcuts, and even website inspection tools. And guess what? You can do all this with just a bit of JavaScript. Here's how you can protect your site like a pro—easily and without plugins!

Why Disable These Features?

Prevent Content Theft: Protect your original articles, images, and other intellectual property from being copied or downloaded.

WhatsApp Channel Join Now
Telegram Channel Join Now

Enhance User Experience: Minimise distractions caused by unnecessary actions like accidental copying or pasting.

Improve Website Security: Restrict casual users from accessing your website’s code through developer tools or inspecting elements.

Add JavaScript to Disable Text Selection, Copy-Paste, and More

Here’s how you can implement these protective measures with JavaScript:

1. Disable Text Selection

Use this simple JavaScript code to prevent users from selecting text on your site:

  Best Free Web Hosting for Students & Beginners | Start Your Online Journey Today!

2. Disable Copy and Paste

This code blocks both copy and paste actions on your website:

3. Disable Keyboard Shortcuts

Prevent users from using common shortcuts like Ctrl+C, Ctrl+V, or Ctrl+Shift+I:

4. Disable Right-Click and Website Inspection

Stop users from right-clicking or opening developer tools:

Steps to Add JavaScript to Your Website

For WordPress Users

    • Navigate to Appearance > Theme Editor or use a plugin like Insert Headers and Footers.
    • Add the JavaScript code within <script> tags in the header or footer.

For HTML Websites

    • Open your HTML file.
    • Add the JavaScript code between <script> tags before the closing </body> tag:

Refresh your site and try performing the disabled actions to ensure everything works correctly.

Final Thoughts – Conclusion

Disabling text selection, copy-paste, keyboard shortcuts, and website inspection tools using JavaScript is a smart way to add an extra layer of protection to your website. While these measures aren’t completely foolproof, they effectively discourage casual users from misusing your content.

Remember, striking the right balance between protecting your site and ensuring a positive user experience is key. Use these techniques wisely and sparingly to safeguard your valuable content without inconveniencing genuine visitors. With just a few lines of JavaScript, you can create a more secure and user-friendly website.

Affiliate Disclosure: Some links in this article may be affiliate links. If you use them, we may earn a small commission at no extra cost to you. This helps support our blog and content. Read full disclosure

Discover more from MTECH4YOU BLOG

Subscribe to get the latest posts sent to your email.

Was this article helpful?
YesNo
Vijay Joshi's avatar

I am a Senior WordPress (CMS) Website Designer and Digital Marketing Expert with over 9 years of experience, having successfully delivered more than 500 websites to clients.

Leave a Comment

Discover more from MTECH4YOU BLOG

Subscribe now to keep reading and get access to the full archive.

Continue reading