Prevent Copying from page. Ctrl+C or Prevent Selection

Hello,
How can I prevent copying from my website or even select text? Right Click Protect by Wix is good, but it does not match the aspirations.

It will be much appreciated if anyone provides a code

my solution
create an event in text, page or any element that wants to put the protection of ctrl c, v
and add the event

export function text1_mouseIn (event) {
wixWindow.copyToClipboard (“Copehight”)
}
export function text1_mouseOut (event) {
wixWindow.copyToClipboard (“Copehight”)
}

this way when the staff hover over the text to select, the word “Copehight” will be automatically transferred to their clipboard and when removing the mouse from the text the same thing will happen,
an easier way to make this work for the home page would be to put it this way

export function page1_mouseIn (event) {
wixWindow.copyToClipboard (“Copehight”)
}
export function page1_mouseOut (event) {
wixWindow.copyToClipboard (“Copehight”)
}

this way the user may even be able to copy the text, but when he leaves the page to paste, the word “Copehight” will be automatically transferred to his clipboard

one way that you can get around this would be using the keys
win + v, which shows all the copied things, this way they can still paste

but in any case, it would be a way to make improper coping difficult

any other updates on this, but also if a table is what im trying to protect?

If your site is connected to your own domain, you can do the following:

  1. Go to Site Dashboard > Settings > Custom Code

  2. Create the following code snippet add it to the head and apply to the relevant page.

<style>
* {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>

That worked!!! Thank you so much, its been an issue for a while but this is perfect!

@J.D. what is that kind of code?

Looks strange for me. Are you still using JS-Syntax, or what is it?

It’s CSS.

@Shane, I changed it a little bit, so it’ll cover h1-h6 too.

so the h1-h6 is the heading text? ok thanks

Awesome :sunglasses: Thank you

This works but search bar/ login stopped working. You can’t type in search bar or login lightbox (mobile does not work, desktop works) if these CSS are disabled.

Hi thanks for your help!!!
It works perfectly but the problem is when ever the page is opened its continuously showing a popup message which irritates user… can you please resolve this?

It worked. Thanks for the help!

for mobile:
Let’s refine the approach to ensure that we only disable copying and text selection without affecting scrolling or clicking on links. Here’s the revised code:

  1. Open Wix Editor: Log in to your Wix account and open your site in the Wix Editor.

  2. Add Custom Code in Settings:

    • Go to the “Settings” tab on the left side of the editor.
    • Select “Custom Code” and then click “Add Custom Code.”
    • Choose “Add to All Pages” if you want the code to apply site-wide.
    • Paste the following code in the text area:
<script>
    document.addEventListener('DOMContentLoaded', function() {
        // Disable long press context menu on mobile devices
        document.addEventListener('contextmenu', function(event) {
            event.preventDefault();
        });

        // Disable text selection
        document.addEventListener('selectstart', function(event) {
            event.preventDefault();
        });

        // Disable copy functionality
        document.addEventListener('copy', function(event) {
            event.preventDefault();
        });

        // Allow touch events to prevent blocking scrolling and link clicks
        document.addEventListener('touchstart', function(event) {
            if (event.touches.length === 1) {
                var target = event.target;
                if (target.tagName !== 'A') {
                    var preventCopy = function(e) {
                        e.preventDefault();
                        target.removeEventListener('contextmenu', preventCopy);
                    };
                    target.addEventListener('contextmenu', preventCopy, { once: true });
                }
            }
        }, { passive: true });

        // Apply CSS to disable user selection
        var style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = `
            body, a {
                -webkit-user-select: none; /* Safari */
                -ms-user-select: none; /* IE 10+ */
                user-select: none; /* Standard syntax */
            }
        `;
        document.getElementsByTagName('head')[0].appendChild(style);
    });
</script>
  1. Placement: Set the code to load in the “Body - end” section to ensure it loads after the rest of your content.

  2. Name the Code: Give the custom code a name like “Disable Copy on Mobile.”

  3. Apply to All Pages: Ensure it’s applied to all pages if needed.

  4. Save and Publish: Click “Apply” and then publish your site to make the changes live.

This script:

  • Disables the context menu on long press.
  • Disables text selection and copying.
  • Ensures scrolling and link clicking are not blocked by making the touchstart listener passive and only preventing the context menu if the target is not a link.

This should effectively prevent copying without interfering with other functionalities like scrolling and clicking links.

I uploaded a spreadsheet using a html add and then popped this at end of the html and worked a treat! Now nobody can cut and paste from what is a curated list that took me days…

This is amazing, this other set of code, for side wide. Thanks so much for sharing! The only thing it didn’t work on was if you upload a doc into a page using a HTML snippet for that I used the other code below.