Create a Disable Right Click, Copy, Cut & Paste using JavaScript Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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 for each operation. We can use this application for the input fields that are highly concerned with security, like passwords, OTP, etc. where the user cannot paste the passwords from other sources and also cannot view the page source code. Preview Image PrerequisitesHTMLCSSJavaScriptApproachFirstly, we need to create the application structure using HTML tags like <div>, <h1> for the heading (GeeksforGeeks Disable Application>, <input> that will take the input from the user. <p> to display the count values when the user performs the operations.Then, we will create the styling file for the basic styling of our application, like the alignment of the components, padding of fields, color structure, and scheme of the elements.In the main JavaScript file, firstly, we are getting references to various HTML elements by using their IDs like a message (this is the element for showing the error message).Then we initialize the values of all the counts with 0. Now, by using the event listeners, we are setting up the 'context menu' for operations of right-click, copy, and paste on the inpBox element. For example, when the right-click event occurs, it prevents displaying the browser's default context menu, and simultaneously, the value of the counter is also incremented.The function for showing the error message is created that passes the argument in the 'errorMessage' element. Using the setTimeOut function, the message disappeared after 2 seconds.Example: This example shows the use of the above-explained approach. HTML <!-- HTML FILE --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> GeeksforGeeks Disable Application </title> <link rel="stylesheet" href="./style.css"> </head> <body> <div class="container"> <h1> GeeksforGeeks Disable Application </h1> <input class="input-box" type="text" id="myInput" placeholder="Enter Text"> <div class="warning-message" id="message" style="display: none;"> </div> <p>Right-click Count: <span id="rightClickCounter"> 0 </span> </p> <p>Copy Count: <span id="copyCounter"> 0 </span> </p> <p>Paste Count: <span id="pasteCounter"> 0 </span> </p> </div> <script src="./script.js"></script> </body> </html> CSS /* Style.css */ body { font-family: Arial, sans-serif; background-color: #f2f2f2; } .container { max-width: 400px; margin: 0 auto; padding: 20px; background-color: #fff; border: 1px solid #ccc; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); border-radius: 5px; } h1 { color: #00a63f; text-align: center; font-size: 24px; } .input-box { width: 80%; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 5px; outline: none; display: block; margin: auto; } .warning-message { color: red; font-size: 14px; margin-top: 5px; text-align: center; } JavaScript // Script.js document.addEventListener( "DOMContentLoaded", function () { let inpBox = document.getElementById( "myInput"); let errorMessage = document.getElementById( "message"); let rightClickCnt = document.getElementById( "rightClickCounter"); let copyCounter = document.getElementById( "copyCounter"); let pasteCounter = document.getElementById( "pasteCounter"); let rightCnt = 0; let copyCnt = 0; let pasteCnt = 0; // Function For Right Count inpBox.addEventListener( "contextmenu", function (e) { e.preventDefault(); rightCnt++; rightClickCnt.textContent = rightCnt; showErrorMsg( "Right-clicking is disabled." );} ); // Function For Copy Count inpBox.addEventListener( "copy", function (e) { e.preventDefault(); copyCnt++; copyCounter.textContent = copyCnt; showErrorMsg( "Copying is disabled." );} ); // Function for Paste Count inpBox.addEventListener( "paste", function (e) { e.preventDefault(); pasteCnt++; pasteCounter.textContent = pasteCnt; showErrorMsg( "Pasting is disabled." );} ); // Function for Display Error Message function showErrorMsg(message) { errorMessage.innerText = message; errorMessage.style.display = "block"; setTimeout(function () { errorMessage.style.display = "none"; }, 2000);} } ); Output: Comment More infoAdvertise with us Next Article Create a Disable Right Click, Copy, Cut & Paste using JavaScript G gauravggeeksforgeeks Follow Improve Article Tags : HTML Geeks Premier League 2023 Similar Reads 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 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 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 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 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 Ctrl + C in JavaScript ? Disabling Ctrl+C in JavaScript involves intercepting the keyboard event and preventing the default action associated with the combination. There are several approaches to disable Ctrl+C in JavaScript which are as follows: Table of Content Using Event ListenersModifying the clipboard eventUsing Event 2 min read How to Copy the Text to the Clipboard in JavaScript? The document.execCommand("copy") method is commonly used to Copy the Text to the Clipboard, allowing developers to copy text programmatically, making it available for pasting elsewhere. To copy text from an input box using JavaScript, first use 'document.getElementById()' to access the input element 1 min read How to Create Keyboard Shortcuts in JavaScript ? This article will demonstrate how to create keyboard shortcuts in JavaScript. We can manually set user-defined functions for different shortcut keys. Keyboard shortcuts allow users to perform actions quickly by pressing a combination of keys, such as Ctrl + S for saving, Ctrl + C for copying, or cus 4 min read What is JavaScript Strict mode and how can we enable it ? JavaScript is a forgiving language as it ignores developers' or programmers' silly mistakes or errors in code like termination of the statement, variable declaration, the wrong data type of variable, hoisting issues, and many more. Sometimes these errors give unusual results which difficult for prog 4 min read Like