Disable Copy or Paste action for text box?

Last updated on April 29th, 2020 at 03:43 am

Reading Time: < 1 minute

I have Three solutions in my mind:

First Is –>

Use ——-> oncopy=”return false” onpaste=”return false”

Name: 
<input type="textbox" id="name" oncopy="return false" onpaste="return false" ><br/>
Name:

Second is –> With Jquery ,Use e.preventDefault();

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script>
$('#name').bind("cut copy paste",function(e) {
          e.preventDefault();
      });
</script>

</head> 
Name: 
<input type="textbox" id="name" >
Name:

Third is –>With Jquery , Use return false


<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script>

$( "#name" ).on( "copy cut paste drop", function() {
                return false;
        });
</script>

</head> 
Name: 
<input type="textbox" id="name" >
Name:
Spread the Code

GEM

Author

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *