I suppose it was inevitable that someone would figure out how to disable the right click button. And on the surface this seems like a great idea. I mean, you can keep people from looking at the HTML code that you’ve worked so hard on. Better yet, they cannot steal that great JavaScript thingy that took you a week to debug and they cannot “borrow” your images. Sounds very cool, right?

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.

<script language="JavaScript">
function right(e) {
if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 2 || event.button == 3)) {
alert("Sorry, Right Mouse Functions Denied, NO ENTRY");
return false;
}
return true;
}
document.onmousedown=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=right;

But just be sure of one thing: that you have a really good reason for implementing this.

Remember this function will not work for Netscape, if the user has disabled JavaScript or in older browsers. Also it does not clear the internet cache (the user can just get the files from there if he wants), disable the “save” on the menu, nor will it prevent your page from being downloaded by a site grabbing utility.

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.