Prevent selection and copying

I want inactive selection and copying text on html page. when I used Javascript and inactive right click, you can use Ctrl + V !!

+3
source share
3 answers

You can not. Do not even try. Do not annoy your users.

If you publish it online, you can copy it. Technically, it is already copied as soon as the user sees it. As Coltium pointed out, all methods can be circumvented. Hell, you can see the source code. You can twist raw data from the command line, not a single JS / IMG / layer hacker can prevent this.

+6
source

. javascript- ( ). , ( ). ( ).

+3

, , , , , .

www.dynamicdrive.com, Java- . , . " Script" " Script".

Script:

/***********************************************
* Disable Text Selection script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
    target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
    target.style.MozUserSelect="none"
else //All other route (ie: Opera)
    target.onmousedown=function(){return false}
target.style.cursor = "default"
}

//Sample usages
//disableSelection(document.body) //Disable text selection on entire body
//disableSelection(document.getElementById("mydiv")) //Disable text selection on element with id="mydiv"

Script:

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com
var message = "Function Disabled!";

///////////////////////////////////
function clickIE4() {
    if (event.button == 2) {
        alert(message);
        return false;
    }
}

function clickNS4(e) {
    if (document.layers || document.getElementById && !document.all) {
        if (e.which == 2 || e.which == 3) {
            alert(message);
            return false;
        }
    }
}

if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown = clickNS4;
} else if (document.all && !document.getElementById) {
    document.onmousedown = clickIE4;
}

document.oncontextmenu = new Function("alert(message);return false")
0

Source: https://habr.com/ru/post/1711471/


All Articles