How to disable cut copy and paste using jQuery

Follow us

This can be achieved using bind() method of jQuery.

The bind() is an inbuilt method in jQuery which is used to attach one or more event handlers for selected element and this method specifies a function to run when an event occurs.

Syntax:
$(selector).bind(event,data, function{});

To make it work, you would need to add cut, copy and paste events on which the bind will work. Here e.preventDefault() will prevent from the respective events that we have mentioned.

Here is sample example of how to disable the cut/copy/paste using jQuery :

<!DOCTYPE html>
<html>
	<head>
		<title>Example : how to disable cut copy and paste using jquery </title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				 $('#textbox').bind('copy paste cut',function(e) { 
				 e.preventDefault(); //disable cut,copy,paste
				 alert('cut,copy & paste options are disabled !!');
				 });
			});
		</script>
	</head>
	<body>
		<label>Demo Text Box</label>
		<input type="text" name="textBox" id="textbox" />
	</body>
</html>