Table of Contents

Disable F12 Inspect Element โ€“ How to Disable Right Click, F12, and Copy-Paste on Any Website Using JavaScript

Editorial Team 4 min read SEO Tips & Guides

Table of Contents

    If you run a website, chances are you donโ€™t want people to inspect your code, copy-paste your content, or steal your images. The browserโ€™s Inspect Element (F12) and Right-Click menu make it very easy for users to copy content or view the source code.

    Thatโ€™s why many developers and website owners want to disable F12 Inspect Element, right-click, and copy-paste using JavaScript.

    In this detailed guide, weโ€™ll cover:

    • Why you may want to disable right-click and F12
    • How to use JavaScript snippets to block these actions
    • How to add the same code in WordPress functions.php
    • Best practices (and limitations) when trying to hide your websiteโ€™s source code
    Disable F12 Inspect Element and right-click using JavaScript

    Why Disable F12 and Right Click?

    There are several reasons why website owners choose to block these actions:

    1. Content Protection โ€“ Prevent users from copying your text or images.
    2. Security Reasons โ€“ Avoid casual visitors from inspecting sensitive scripts.
    3. Professional Branding โ€“ Keep your code structure hidden.
    4. Plagiarism Prevention โ€“ Stop scrapers from stealing your work.

    โš ๏ธ Important Note:

     Disabling right-click or F12 does not guarantee 100% security. Advanced users can still bypass these restrictions. But it does stop the majority of casual content thieves.

    Methods to Disable Right Click, F12, and Copy-Paste

    There are two main methods:

    1. Using JavaScript in HTML files
    2. Adding a PHP function in WordPress (which outputs JavaScript in footer)

    Weโ€™ll cover both in detail.

    Method 1: Disable F12 Inspect Element and Right Click with JavaScript

    The easiest way is to insert a small JavaScript snippet inside your <head> or before the </body> tag.

    <script>
        // Disable Right Click
        document.addEventListener('contextmenu', function(event) {
            event.preventDefault();
        });
    
        // Disable F12 and Ctrl+U
        document.addEventListener('keydown', function(event) {
            // Disable Ctrl+U
            if (event.ctrlKey && (event.key === 'u' || event.key === 'U')) {
                event.preventDefault();
            }
            // Disable F12 (Inspect Element)
            if (event.keyCode === 123) {
                event.preventDefault();
            }
        });
    
        // Disable Text Selection (Copy-Paste)
        document.addEventListener('selectstart', function(event) {
            event.preventDefault();
        });
    </script>

    ๐Ÿ‘‰ Save the file and reload your webpage.
    Now, users wonโ€™t be able to:

    • Right-click on your page
    • Press F12 to open DevTools
    • Press Ctrl+U to view the source code
    • Select and copy text

    Method 2: Disable F12 and Right Click in WordPress (functions.php)

    If you are using WordPress, you can add this function inside your functions.php file:

    function disable_right_click() {
        echo "
        <script>
            document.addEventListener('contextmenu', function(event) {
                event.preventDefault();
            });
            document.addEventListener('keydown', function(event) {
                // Disable Ctrl+U
                if (event.ctrlKey && (event.key === 'u' || event.key === 'U')) {
                    event.preventDefault();
                }
                // Disable F12 (Inspect Element)
                if (event.keyCode === 123) {
                    event.preventDefault();
                }
            });
            document.addEventListener('selectstart', function(event) {
                event.preventDefault();
            });
        </script>
        ";
    }
    add_action('wp_footer', 'disable_right_click');

    How This Works:

    • The function outputs JavaScript code in your websiteโ€™s footer.
    • It disables right-click, F12, Ctrl+U, and text selection.
    • Works across all pages of your WordPress site.

    Limitations of Disabling F12 and Right Click

    Even though this method blocks most casual users, there are limitations:

    • Advanced Users Can Still Bypass โ€“ Developers can disable JavaScript or use browser extensions.
    • May Affect Accessibility โ€“ Users who rely on right-click for accessibility may face issues.
    • Not Foolproof โ€“ Your HTML, CSS, and JS are still downloadable from server requests.

    ๐Ÿ‘‰ Mozilla Developer Docs on DevTools explain why blocking F12 is not always effective.

    Best Practices to Protect Your Website

    Instead of relying only on JavaScript tricks, combine these strategies:

    • Use Watermarks on images to prevent theft.
    • Implement Server-Side Protections like disabling hotlinking.
    • Add DMCA Protection for your site.
    • Regularly monitor plagiarism using tools like Copyscape.
    • Combine right-click disable + legal measures for stronger protection.

    Try our Plagiarism Checker Tool to detect stolen content.

    Conclusion

    Disabling F12 Inspect Element, right-click, and copy-paste using JavaScript is a quick way to protect your website from casual users trying to steal your content.

    • For static sites โ†’ use the JavaScript snippet
    • For WordPress โ†’ use the functions.php method

    But remember โ€” this is only a basic protection layer. Skilled users can still access your source code. For complete protection, combine it with server-side measures, DMCA protection, and watermarks.