JavaScript preventDefault() Event Method

The preventDefault() Method cancels the event if it can be canceled, meaning that it stops the default action that belongs to the event. For example- Clicking on a “Submit” button, prevent it from submitting a form. 

Syntax:

event.preventDefault()

Parameters: It does not accept any parameter.

How to disable right click on web page using JavaScript ?

Disabling right-click on a web page can be done using the DOM Events. It is a client-side action, and it can be achieved using JavaScript.

However, it’s important to note that attempting to prevent right-clicking is not a foolproof method for protecting your content, as users can easily bypass it by disabling JavaScript or using browser features.

To disable right click on web page in JavaScript we can use the methods given below:

Table of Content

  • HTML DOM addEventListener() Method
  • JavaScript preventDefault() Event Method

Similar Reads

HTML DOM addEventListener() Method

The addEventListener() Method attaches an event handler to the specified element....

JavaScript preventDefault() Event Method

The preventDefault() Method cancels the event if it can be canceled, meaning that it stops the default action that belongs to the event. For example- Clicking on a “Submit” button, prevent it from submitting a form....

Example for disabling the Right Click on Web Page

The below examples uses the above mentioned method to disable the right click....