I need a field that will show content that can not be written or copied or pasted in any way.
I need a field that will show content that can not be written or copied or pasted in any way.
If you want to have a input
, then try like this:
The readonly
attribute prevents the user from modifying its value.
If the event onmousedown
, we configure a return false
, we will avoid that you can select the content and therefore can not copy.
Example:
<input type="text" value="Texto" readonly onmousedown="return false;" />
To avoid that the content of input
can be selected by starting the selection from the outside, it is necessary to disable the selection of all document
Example:
// Deshabilitamos la seleccion
document.addEventListener('mousedown', function(evt) {
evt.preventDefault();
return false;
});
// BONUS - Deshabilitamos el menu contextual
document.addEventListener('contextmenu', function(evt) {
evt.preventDefault();
return false;
});
Texto fuera y antes del campo <br/>
<input type="text" value="Texto" readonly /><br/>
Texto fuera y despues del campo
Try this:
It allows to style in DIV so that it resembles a text type input, so it can not be modified, however the copy of the content is not resolved.
CSS3
#input {
-moz-appearance: textfield;
-webkit-appearance: textfield;
background-color: white;
background-color: -moz-field;
border: 1px solid darkgray;
box-shadow: 1px 1px 1px 0 lightgray inset;
font: -moz-field;
font: -webkit-small-control;
margin-top: 5px;
padding: 2px 3px;
width: 398px;
}
HTML
<div id="input">Tu contenido aquí</div>
Dear, although the input that I added can be selected, it can not be copied and it is also disabled, thus avoiding copying or changing its content.
Greetings.
<input type="text" disabled value="Soy un texto" oncopy="return false;"/>
From html in the body part, there are attributes that can be used for these cases: oncopy, oncut and onpaste, which by default come true (true), so we would have to give them false (false) value example:
<body oncopy="return false" oncut="return false" onpaste="return false">
<input type="text" name="hola" readonly="true" value="test" />
</body>
Greetings