But there is another viewpoint, one that is not so “webmaster-centric” (great word huh?). Keep in mind that your job as a webmaster is to (a) attract visitors, (2) give your visitors a reason to keep coming back, (3) inform or entertain them, and possibly (4) sell them something.
The web is intended as a way to share information all over the world. Note the word “share”. This entire internet thing is all about communication – the ability to communicate with anyone, anywhere, anytime.
Think about it another way. If HTML was intended to be hidden, it would have been designed that way. It would have been easy to create an HTML specification which required it to be compiled (for example) and hiding pages could have been written into the specifications.
But it has not. In point of fact, it has never been written into any HTML specifications.
My point is simple. Keep the web free and open. One of the things that’s great about the world wide web is the ability to just right click on a page at any time and look at the source code. This is a wonderful way for someone to learn about HTML. Think how frustrated he feels when a message comes back saying “tough luck – learn somewhere else”.
And that’s precisely the message that someone will get if you disable the right click on your site. “My stuff is sacred, I don’t care if you want to learn how I did it. I’m better than you.” Personally, I’ll just go somewhere else – there are millions of web sites and I don’t need to go to one this hostile. Not ever again. In point of fact, generally I will NEVER ever visit a web site again that pulls this stunt.
All that said, here’s the code to do it, if you really, really want to. This, by the way, was borrowed from a site which was “protected” with this exact same code.
But just be sure of one thing: that you have a really good reason for implementing this.
In fact, this really doesn’t work well. There is no foolproof way to keep someone from getting at your HTML code – perhaps for good reason.