Webpage Workshop: Home » FAQ: How can I hide my source code?

FAQ: How can I hide my source code?

Answer: You can't, and even if you could you shouldn't. Many people try different techniques to try and hide their source code from their visitors, but each and every method you can use is not guaranteed to work in all situations.

Disabling the 'right-click' menu is one such way that people attempt to stop you from viewing their source code. It might work for some people running Internet Explorer, but this method is easy to bypass. Simply by holding the right-mouse-button and then pressing return before releasing the button will, in most cases, allow access to the context menu. You can also access the source code by selecting 'View > Source' (or similar) on the menu bar of most browsers.

The drawbacks of this technique are quite obvious. Firstly, it relies completely on JavaScript - so disable JavaScript and this technique is useless. Secondly, it only works in Internet Explorer - so Netscape users are immune, as are a plethora of other browsers out there. Finally, the Apple Mac has no right-mouse-button - so how are you supposed to disable something that doesn't exist?

Another commonly used technique is to use JavaScript to encrypt your source code and write the contents to the browser window. This results in any attempt to view source being displayed as random letters and numbers. Disable JavaScript, however, and your page will be 100% blank. This means that your visitors will won't only be unable to see the source code, but they will also be unable to see the page! This method can also be overcome, but it is slightly more tricky.

The real reason behind not hiding your source code is that the Internet is a way of sharing information and ideas - not hiding them - and if you don't want people seeing your ideas then you shouldn't put them on the web, but rather dig a big hole and bury them where no one can find them or better still keep them in your head. Once a visitor goes to your site, they download the whole page to their computer automatically and so they have a copy that they can do whatever they want to it.

Copyright laws pertaining to work on the Internet state that all of your published materials (i.e. original text, original images) is considered copyrighted as soon as you created it - it does not however extend to the source code of your site (i.e. HTML) and so you cannot stop people from copying your code, but you can do something about people stealing your text or images.

Related links