Here is the script that disables right mouse button click in an ASP.NET page. You can put this script in your head tag.
- <head id="Head1" runat="server">
- <title>Web Page</title>
- <script type="text/javascript">
- var message = "Function Disabled!";
- function clickIE4() {
- if (event.button == 2) {
- alert(message);
- return false;
- }
- }
- function clickNS4(e) {
- if (document.layers || document.getElementById && !document.all) {
- if (e.which == 2 || e.which == 3) {
- alert(message);
- return false;
- }
- }
- }
- if (document.layers) {
- document.captureEvents(Event.MOUSEDOWN);
- document.onmousedown = clickNS4;
- }
- else if (document.all && !document.getElementById) {
- document.onmousedown = clickIE4;
- }
- document.oncontextmenu = new Function("return false")
- </script>
- </head>
The key is to capture the mouse down click event and in the event handler, show the message box and not display the browser context menu.

Michael WagnerPosted Feb 18, 2021, 2:42 PM
Nice job, thanks!
Pankajkumar PatelPosted Aug 16, 2019, 12:55 AM
Nice one ...
Nithish ReddyPosted May 29, 2018, 5:35 AM
Hi Pankaj , can we disable right on pdf file using javascript or jquery ?
Laxita SolankiPosted Mar 18, 2013, 4:15 AM
thnx i need this code