Disable Right Click

This code disables the browser’s right-click menu by listening for the contextmenu event, which occurs when the user right-clicks anywhere on the page. When the event is detected, event.preventDefault() stops the browser from showing its default menu, and an alert message is displayed to inform the user that right-clicking is disabled.

<!DOCTYPE html>
<html>
<body>

  <h2>Right Click is Disabled</h2>

  <script src="script.js"></script>

</body>
</html>
// Add event listener for right click
document.addEventListener("contextmenu", function(event) {

  // Prevent default right-click menu
  event.preventDefault();

  // Show alert message
  alert("Right click is disabled!");
});

Leave a Reply

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