Disable Copy Text in Javascript & CSS
// (A) PREVENT CONTEXT MENU FROM OPENING
document.addEventListener(“contextmenu”, (evt) => {
evt.preventDefault();
}, false);
// (B) PREVENT CLIPBOARD COPYING
document.addEventListener(“copy”, (evt) => {
// (B1) CHANGE THE COPIED TEXT IF YOU WANT
evt.clipboardData.setData(“text/plain”, “Copying is not allowed on this webpage”);
// (B2) PREVENT THE DEFAULT COPY ACTION
evt.preventDefault();
}, false);
CSS Code
/* (C) NO SELECT + HIGHLIGHT COLOR */
* { user-select: none; }
*::selection { background: none; }
*::-moz-selection { background: none; }