Necroyeti Asked: 2020-12-06 11:50:36 +0800 CST 2020-12-06 11:50:36 +0800 CST 2020-12-06 11:50:36 +0800 CST How to block copy and paste in an input? 772 I have an input... <input type="text"> How do I block the commands (control+c and control+v) and right click, copy or paste? html 3 Answers Voted Best Answer Bender Paisa 2020-12-06T11:57:18+08:002020-12-06T11:57:18+08:00 With native JavaScript you could do the following: window.onload = function() { var myInput = document.getElementById('bloquear'); myInput.onpaste = function(e) { e.preventDefault(); alert("esta acción está prohibida"); } myInput.oncopy = function(e) { e.preventDefault(); alert("esta acción está prohibida"); } } <input type="text" id="bloquear"> Or with jQuery : $(document).ready(function(){ $("#bloquear").on('paste', function(e){ e.preventDefault(); alert('Esta acción está prohibida'); }) $("#bloquear").on('copy', function(e){ e.preventDefault(); alert('Esta acción está prohibida'); }) }) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="bloquear"> Jorgesys 2020-12-06T11:57:50+08:002020-12-06T11:57:50+08:00 Using html, you can add to your<body> oncopy="return false"to avoid copying ( Ctrl+ c), and onpaste="return false"to avoid sticking ( Ctrl+ v): Example: <body oncopy="return false" onpaste="return false"> <input type="text"> This is a demo: <body oncopy="return false" onpaste="return false"> <input type="text"> <p>Trata de seleccionar y copiar este texto (Ctrl+c) y pegarlo (Ctrl+v) ...</p> humano 2020-03-10T09:50:19+08:002020-03-10T09:50:19+08:00 There is a chrome extension that bypasses the "onpaste" restrictions, these methods do not work if the user has it installed. https://chrome.google.com/webstore/detail/dont-fuck-with-paste/nkgllhigpcljnhoakjkgaieabnkmgdkb
With native JavaScript you could do the following:
Or with jQuery :
Using html, you can add to your
<body>
oncopy="return false"
to avoid copying ( Ctrl+ c),and
onpaste="return false"
to avoid sticking ( Ctrl+ v):Example:
This is a demo:
There is a chrome extension that bypasses the "onpaste" restrictions, these methods do not work if the user has it installed. https://chrome.google.com/webstore/detail/dont-fuck-with-paste/nkgllhigpcljnhoakjkgaieabnkmgdkb