How to disable right click on web page using JavaScript ? Last Updated : 05 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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() MethodJavaScript preventDefault() Event MethodHTML DOM addEventListener() MethodThe addEventListener() Method attaches an event handler to the specified element. Syntax: document.addEventListener(event, function, useCapture) JavaScript preventDefault() Event MethodThe 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. Example for disabling the Right Click on Web PageThe below examples uses the above mentioned method to disable the right click. Example 1: This example disable the right click by adding an event listener for the "contextmenu" event and calling the preventDefault() method. html <!DOCTYPE html> <html lang="en"> <head> <title> How to disable right click on web page using JavaScript ? </title> </head> <body style="text-align: center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> How to disable right click on web page using JavaScript ? </h3> <button onclick="Fun_call()"> Disable Right Click </button> <h3 id="GFG" style="color:green;"> </h3> <script> let elm = document.getElementById("GFG"); function Fun_call() { document.addEventListener('contextmenu', event => event.preventDefault()); elm.innerHTML = "Right click disabled"; } </script> </body> </html> Output: Example 2: This example disables the right-click on the image by adding an event listener for the "contextmenu" event and calling the preventDefault() method. Because, Sometimes we do not want the user to save the image. html <!DOCTYPE html> <html lang="en"> <head> <title> How to disable right click on web page using JavaScript ? </title> </head> <body style="text-align: center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> How to disable right click on web page using JavaScript ? </h3> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20190521140445/gfglogo2.png" /> <br><br> <button onclick="Fun_call()"> Disable Right Click </button> <h3 id="GFG" style="color:green;"> </h3> <script> let elm = document.getElementById("GFG"); function Fun_call() { document.addEventListener("contextmenu", function (e) { if (e.target.nodeName === "IMG") { e.preventDefault(); } }, false); elm.innerHTML = "Right click disabled on image"; } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to disable right click on web page using JavaScript ? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to disable right-click option using the jQuery ? The bind() method in jQuery is used to attach one or more event handlers for selected element and this method specifies a function to run when an event occurs. Syntax: $(selector).bind(event, data, function);Parameters: This method accepts three parameters as mentioned above and described below: eve 2 min read How to Disable Textarea using JavaScript? This article will show you how to disable the textarea using JavaScript. Disabling a textarea using JavaScript can be done by setting the disabled property of the textarea element to true. This prevents the user from editing the content of the textarea. There are some reasons to use disabled textare 2 min read How to Disable Scrolling Temporarily using JavaScript? Disabling scrolling temporarily using JavaScript means preventing users from scrolling a webpage during specific interactions, such as when a modal is open or a loading screen is displayed. Scrolling can be disabled using JavaScript using 2 methods:Table of ContentUsing window.onscroll functionSetti 2 min read How to disable radio button using JavaScript ? Radio buttons let users select one option from many, commonly used in forms. Sometimes, based on a user's previous choice, certain options need to be disabled. For example, if a user selects "No" to playing games, we can disable related game options. Using JavaScript, about 65% of forms use such log 4 min read Create a Disable Right Click, Copy, Cut & Paste using JavaScript In this article, we have created a simple user interface using HTML and CSS, where there is an input field on which Right-Click, Copy, Cut, and Paste counts are displayed. When the user tries to perform these operations, a warning or error message is displayed, and the counter value is incremented f 3 min read How to disable Copy, Paste, Cut and Right Click using jQuery ? The ctrl+c, ctrl+v, ctrl+x and a right-click of the mouse is used to copy, paste and cut anything from anywhere. It can be disable for particular task or page. Let see how to disable cut, copy, paste and right-click. It can be done in two ways: By using an on() method By using keydown() and mousedow 3 min read How to Disable Ctrl+V (Paste) in JavaScript? What is Ctrl + V ?The ctrl+V is a keyboard shortcut used to paste anything from anywhere. It can be disabled for a particular task or page. Let's see how to disable cut, copy, paste, and right-click. To disable the ctrl+V (paste) keyboard shortcut in JavaScript, you would typically capture the keydo 3 min read How to Disable Specific Readio Button Option using JavaScript? In this article, we will disable a specific radio button using JavaScript. Disabling specific radio button options using JavaScript involves targeting the specific option and then set its disabled property to true. This can be done by selecting the radio button option and modifying its disabled prop 2 min read How to Open a Link Without Clicking on it using JavaScript? To open a link without clicking on it we can use the onmouseover method of JavaScript. The link will open when the mouse moves over the text. It returns a newly created window, or NULL if the call gets failed. Syntax:window.open( URL, name, Specs )Note: Allow Pop-up of Web Browser. Example 1: URL is 1 min read How to disable HTML links using JavaScript / jQuery ? Given an HTML link and the task is to disable the link by using JavaScript/jQuery. Approach 1: Disable HTML link using JavaScript using setAttribute() Method. JavaScript setAttribute() Method: This method adds the defined attribute to an element and gives it to the passed value. In case of the speci 5 min read Like