How to Disable Right Click using JQuery

Disable Right Click using JQuery

In this example, We will show you how to disable right click using JQuery. The example has been tested with environment and output shared in the same post.

Script Code

$(function() {
	$(this).bind("contextmenu", function(event) {
		alert("Sorry, This functionality is disabled");
		event.preventDefault();
	});
});

Complete Example Code

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>How to disable right click using jquery</title>
</head>
<body>

	<h1>Disable Right Click using JQyery</h1>

	<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

	<script type="text/javascript">
		$(function() {
			$(this).bind("contextmenu", function(event) {
				alert("Sorry, This functionality is disabled");
				event.preventDefault();
			});
		});
	</script>

</body>
</html>

Output

When you run the above code on the browser, and try to perform the right click on the page it will alert you by stating the right click functionality has been disabled. The sample output has been shown in the below image screen shot.

How to Disable Right Click using JQuery

References

1. JQuery Website
2. JQuery API Documentation
3. JQuery.bind() function

Hello everyone, I am a Founder of dineshkrish.com.