Click here to Skip to main content
Sign Up to vote bad
good
Dear sir,

How to write a code for disabling view source from mouse right click and choose menu item in menu?

 
in my asp.net page.
Please give me a code.
 
by mohan.
Posted 13 Mar '12 - 22:35


4 solutions

Hi mohan,
Every browser has its built-in functionality to view the source code or the webpage. We can do one thing. That is disabling right click in your page.
 
For disable right click use the following code:
 
<SCRIPT TYPE="text/javascript">
function disableselect(e){
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</SCRIPT>
 

Remember one thing. We can view this source using firebug or some other third party tools. So we cant do this 100%.
  Permalink  
As mentioned by Shivapragasam, it's not worth doing this - you can always use web developer tools such as firebug to view everything you want about a page.
 
All you're going to achieve by disabling right mouse is annoying anyone using your pages, in case they want to use some context menu items.
  Permalink  
Besides diabling right click ,if you want to stop users from using menu item ,
use a popup frame. There you are unable to use menu item....
  Permalink  
You can develop your website using Silverlight.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 415
1 OriginalGriff 315
2 Slacker007 240
3 Maciej Los 240
4 Aarti Meswania 210
0 Sergey Alexandrovich Kryukov 8,953
1 OriginalGriff 7,134
2 CPallini 3,758
3 Rohan Leuva 3,066
4 Maciej Los 2,528


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid