Click here to Skip to main content
15,030,781 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 page.
Please give me a code.

by mohan.
Updated 6-Dec-20 3:22am
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....
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){

Remember one thing. We can view this source using firebug or some other third party tools. So we cant do this 100%.
cjdg08 2 days ago
I think disabling right-click on the web page will not resolve it because it has a shortcut key to View Page Source. I have the same problem, I hope it is possible
You can develop your website using Silverlight.
you cant do it ... :(
but you can hide context menus using
<body  öncontextmenu="return false">

and frustrate the user.. ;))
my friend if you are using 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