I have an input ...
<input type="text">
How do I block the commands (control + c and control + v) and right click, copy or paste?
I have an input ...
<input type="text">
How do I block the commands (control + c and control + v) and right click, copy or paste?
With JavaScript native 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">
Using html, you can add to your <body>
oncopy="return false"
to avoid copying ( Ctrl + c ),
and onpaste="return false"
to avoid hitting ( 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>