Use the preventDefault Method With contextmenu Event to Disable Right Click on a Webpage in JavaScript. This function cancels the event if it can be canceled, which disables the event's default action. For instance, clicking the Submit button will prevent submitting the form.