Click here to Skip to main content
13,767,632 members
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 5 Aug 2005

Disabling the right click on web page

, 12 Aug 2005
Rate this:
Please Sign up or sign in to vote.
Article shows two methods to disable context menu on right click on web page first method can be found on majority of web pages, but second method which cannot be found anywhere is simplest
<!-- HTML for article "Disabling the right click on web page" by Rohit123dighe,Rohit123dighe,Rohit123dighe,Rohit123dighe URL: Article content copyright Rohit123dighe,Rohit123dighe,Rohit123dighe,Rohit123dighe All formatting, additions and alterations Copyright © CodeProject, 1999-2005 --><!----------------------------- Ignore ----------------------------->

Download demo project - 2.57 Kb


Want to protect your source code? Using this code will prevent the vast majority of users from right-clicking over a page and choosing "View source", or right-clicking over an image and saving it.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>

Some times there might be the requirement to disable the pop up menu on click of right button.<o:p>


Programmers may need to disable right click to prevent user from saving the images on the page or viewing the source of the page.


Though disabling right click is not complete solution to save the data, but it will make task difficult, or may be impossible for the rookies.<o:p>


I searched on a net for the solution to this problem and i got following solution.<o:p>

Method 1

      In this method we add a javascript method, in this we check if click is right click or left click if it is right click then a message is displayed like "Right click disabled"<o:p>



<script language="javascript">
status="Right Click Disabled";
Function disableclick(e)
     return false;	

But in this solution if you click the right click it displays the message <o:p>

“Right click disabled”.<o:p>



If we want to remove the messegebox then this solution do not work.<o:p>


  I am having another simple solution to achieve the same result and also it does not show the messegebox.<o:p>


Method 2

          In this method we set the oncontextmenu="return false" in the body part of the page

so body part will look like

<body oncontextmenu="return false">

So whenever user clicks the right mouse button nothing will happen, no message no context menu.<o:p>


 Sometimes there might be requirement to disable the right click on specific control to achive this we have to follow these steps.<o:p>

1.      remove added code in body (i.e. oncontextmenu=”return false”)<o:p>

2.      Add one table and in its row add the control e.g. datagrid control<o:p>

3.      put the oncontextmenu=”return false” in the <tr> for that control<o:p>


So code will look like this<o:p>

   <tr oncontextmenu="return false">
     <asp:datagrid id="dgGrid1">---</asp:datagrid>

So by this method context menu on the right click of right mouse click can be disabled. <o:p>



<!----------------------------- Article Ends ----------------------------->


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
India India
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
Margo Morel22-Jun-14 11:28
memberMargo Morel22-Jun-14 11:28 
Questionnice sir Pin
ntitish14-Mar-13 4:46
memberntitish14-Mar-13 4:46 
GeneralMy vote of 5 Pin
hadi552625-Jul-12 20:49
memberhadi552625-Jul-12 20:49 
GeneralMy vote of 5 Pin
shaminders8-Apr-12 0:07
membershaminders8-Apr-12 0:07 
GeneralThis helped me. Thanks Pin
NeCroFire22-Nov-10 3:56
memberNeCroFire22-Nov-10 3:56 
GeneralRe: This helped me. Thanks Pin
hadi552625-Jul-12 20:50
memberhadi552625-Jul-12 20:50 
Generaluseless trick Pin
anojkumar1-Jul-08 19:47
memberanojkumar1-Jul-08 19:47 
QuestionHow to disable Copy/Past into a TextBox Pin
Sudipta(Bubun)28-Jun-07 21:22
memberSudipta(Bubun)28-Jun-07 21:22 
AnswerRe: How to disable Copy/Past into a TextBox Pin
anil 1kumar23-Oct-07 20:05
memberanil 1kumar23-Oct-07 20:05 
GeneralOther ways to access the menu Pin
Philippe Mori13-Aug-05 9:14
memberPhilippe Mori13-Aug-05 9:14 
GeneralWaste of time Pin
Anonymous13-Aug-05 8:14
memberAnonymous13-Aug-05 8:14 
GeneralWhy you shouldn't do this: Pin
NeverHeardOfMe12-Aug-05 13:18
memberNeverHeardOfMe12-Aug-05 13:18 
QuestionAre you serious?? Pin
JoeySmith7-Aug-05 5:18
memberJoeySmith7-Aug-05 5:18 
GeneralDon't do this PinPopular
ector5-Aug-05 11:40
memberector5-Aug-05 11:40 
GeneralHTML trick... Pin
PixiGreg5-Aug-05 3:59
memberPixiGreg5-Aug-05 3:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05-2016 | 2.8.181116.1 | Last Updated 12 Aug 2005
Article Copyright 2005 by RohitDighe
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid