JavaScript code that displays a pop-up message when the right mouse button is clicked
Mark E.
document.addEventListener("contextmenu", function(event) {
event.preventDefault(); // prevent the default context menu from appearing
alert("Right mouse button is not allowed here!"); // display a pop-up message
});
This code attaches an event listener to the contextmenu
event, which is triggered when the user right-clicks on the page. The preventDefault()
method is called to prevent the default context menu from appearing. Finally, an alert()
function is used to display the message. You can customize the message to suit your needs.