How can i prevent View source in browser?

How can i prevent View source in browser? Without JavaScript.
Who is Participating?
dij8Connect With a Mentor Commented:
It can't be done.  There are tricks, like the right click disabling, but this doesn't help.  You then only need to go to the view menu.  If the menus are gone then on a Windows machine with a windows keyboard you only need to press the context sensitive menu button.  And if even that fails then you only need to go to your cache.  A page needs to be downloaded to be seen.  And in downloading it the user gets the code for free.  There is no way around this.

If your code is so special that it can't be shared then don't put it on the web.  That is the only real answer.  The next closest thing is to turn your scripted functions into server side compiled components and run them on a server that supports what you have written.

Another lame idea but one that makes it just a fraction more difficult than right click/view source is to have your scripts as external files.  But then a person only needs to look at where your scripts are stored (in your source code) to be able to download them directly.
I don't think it's possible...
you have to use javascript, in order to turn off the right click options, or using HTML.encode method.

You can't do it only with HTML.
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

All there is, are tricks to make it harder to view the source-code...but there are many ways to get around these tricks....

And the most forgotten one is that the page you in your history, as soon as you want to view the source go to the specific page in your history and open it in notepad...there you have your source...

So what I'm trying to say, do not try to hide your source...when you do, it will make people more curious what the reason is that you hide your source and will make them want to view it even more...and trust me...when they want...they can!

It is absolutly 100% impossible.

The tricks which make it harder for people to get at it are easily bypassed and tend to lock out other features that people want to use (such as opening a link in a new window).
emelinCommented: deals with this, it's a pretty good summary of what can be done and why there's no use trying. :)
LOL   At least once a week ... and emelin already posted my favourite link
on the subject.

If the browser has to render the code it has to be able to see it.  If the
browser can see it:  I can see it; I can take; I can post it;  and there
is nothing you can do to stop me.

You can go so far as to use a JAVA applet to generate the code so the is
nothing on the source page except the code to load the applet.  I will
still be able to get the code.

Try anything you want.  When you think you have found a way to hide the
source do this:

Using IE5+ type this into the address bar

javascript:str=document.documentElement.innerHTML;document.write('<textarea rows=20 cols=60>'+str+'</textarea>');

The page has been replace with one containing a textarea with all the
code the browser used to render the page.

I don't know of any method, including generation of the code using an applet,
that can prevent capture this way. Any HTML generated by JavaScript is
shown after generation instead of the JavaScript code even if the code
is sourced in.  Instead of seeing the JavaScript you see the result of it.

However if someone comes up with something, I will just defeat it another
way.  This method does not capture the source code,  It captures what the
browser sees and executes to render.  If I can't see it this way then
IE5 can't see it either, and therfore cannot render the page.

Now course the whole page can be done with an applet or flash, but
then it is compiled code.  It is not a WEB page any more.  It is a
browser appliction that requires the user to allow compiled code on
their computer. That is something that more and more users are refusing
to do because it opens them up to viruses and trojan horses.

BTW if you are have trouble with geting pure text off of a page
because they have made it difficult to cut and paste just change
innerHTML to innerText and it will put all the pure text content
into the text area.

BTW, welcome to EE.  Sorry your first question does not have a positive answer.

emelin: The link doesn't work for me.  Is something missing?  Thanks!
Duplicate account??

Well said, COBOLDinosaur.

By the way, nice trick.
This doesnt solve it..but it makes it hard,

1st page of your site has to be viewable (you may put the no right click script on it..but they can still view)

link all other pages as pop-up windows (there are ways to make them maximize as big as users screen..tell me if you want that code
like:   <a href="click me" onClick="MM_openBrWindow('yourpage.html','','width=400,height=400')">click me

now insert that same no right click script on the page as earlier linked to in this discussion by emelin

The only way to get the source is to read the home pages html..find where it links to next page and paste it manually into the address bar of a fresh browser.
kagtha's solution just makes the site unusable to people with JavaScript disabled or unavailable to them and can very easily be bypassed by viewing the contents of the browser's cache.
kagtha's solution is just another trick that is extremely easy to bypass.  If you have a Windows keyboard try pressing the "context sensitive menu" button (the one on the right with the arrow and drop-down menu).  And then select view source.  Done.  And that is before you go to the browser cache.

There is only one gauranteed way of stopping people from viewing your source.  DON'T PUT IT ON THE WEB!
Or just shift+f10 still gives you the menu.  Abad solution unless you want to prevent the viewing of the source by convincing users that they should not use the site because it uses obnoxious rendering techniques.

Hmmm... no one has answered yet...

Q:"How can i prevent View source in browser? Without JavaScript. "

A:<no JavaScript required>

1. Put source on a CD which is copy protected.  
2. Put CD in a steel box.
3. Use duct tape to attach the steelbox to an armed nuclear warhead.  
4. Connect the detonator of the device to a motion detector that will detonate if there is any movement within 10 metres.

Now let's see anybody get that code. :^P

(+ everybody else unable to open the link I submitted)
try instead!
To close this out, I will be making a recommendation to CS
in about a week.  I would appreciate any comments from the
participants on how it should be disposed of.

I think I covered it first for the "it can't be done" statement (psogaa was guesing and wasn't really stating an answer).
It is time to clean this abandoned question up.  

I am putting it on a clean up list for CS.

points to dij8


If anyone participating in the Q disagrees with the recommendation,
please leave a comment for the mods.

Comment from dij accepted as answer.

Thank you
Community Support Moderator
All Courses

From novice to tech pro — start learning today.