HTML page disable copy/paste - JavaScript
Expert User
Verified
Disable the right-click (context menu) to prevent copy-and-paste.
Disable the clipboard copy.
CSS disable select and hide the highlighting of text.
<script> // (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); $(document).bind('keydown', 'ctrl+u', function(e) { e.preventDefault(); return false; },false); </script>
<style> /* (C) NO SELECT + HIGHLIGHT COLOR */ * { user-select: none; } *::selection { background: none; } *::-moz-selection { background: none; } </style>
<p>Disable the right-click (context menu) to prevent copy-and-paste.</p> <p>Disable the clipboard copy.</p> <p>CSS disable select and hide the highlighting of text.</p>
Prevent the below things from a web page so that no one can copy or use your code.
- Disable the right-click (context menu) to prevent copy-and-paste.
- Disable the clipboard copy.
- CSS disable select and hide the highlighting of text.
- Prevent CTRL+S, CTRL+U, CTRL+P and CTRL+R
Comments
Leave a Comment