Click here to Skip to main content
14,935,427 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
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
Updated 6-Dec-20 3:22am
Comments
Manoj Kumar Choubey 30-Apr-14 8:15am
   
please explain exact requirement to disable view source ?

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.
   
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....
   
You can develop your website using Silverlight.
   
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%.
   
you cant do it ... :(
but you can hide context menus using
HTML
<body  öncontextmenu="return false">
...
</body>

and frustrate the user.. ;))
   
v2
my friend if you are using asp.net then many of the code are dynamically created by server on basis of your code.
you dnt need to hide your code becoz in every other process of your page source code will automatiaclly gets changed and by any mean you cannot hide hide source code any buddie can see source code by just go in chrome browser -> setting -> tools -> Developer tools(crtl + shift + i).
   
Technically, you can't. The client has to receive the HTML to display it. You can try to hide it using frames, but some browsers offer the option to view frame source. Also, a savvy user will know how to get at the source even if you use frames.

But as per your need you can do the following:

1. Build the page with Flash.

2. Build the page entirely with javascript in a .js file and then call the .js file from your HTML.

Hope it Helps :)
   
Just, don't do it.

No matter what you do, you can't prevent users from having full access to every bit of data on your website. Any Javascript you code can be rendered moot by simply turning off Javascript on the browser (or using a plugin like NoScript). Additionally, there's no way to disable the ability of any user to simply "view source" or "view page info" (or use wget) for your site.
   

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900