So, You Don't Want Clicks, Huh?

By Joe Burns

Use these to jump around or read it all...
[No Right Click]
[No Left Click]
[No Clicking At All!]

Okay, okay, okay... I give! I'll post a short tutorial on stopping people from clicking on your page! If you haven't visited the HTML Discussion groups then you probably don't know why I'm sounding exasperated.

At least once a day, a question is asked about how to disable someone's right or left click mouse button. The reasoning behind it is that it will somehow stop prying eyes from seeing your code or stop sticky fingers from stealing your images.

I guess there's some validity in the right-click reasoning in that someone new to the game might be put off when they are told No Right Clicking! However, let me point out a couple of things before you begin posting these scripts on every page, thinking it's a lock and key for your valuables.

  • A Web-Head who knows what he or she is doing can get your code or your images no matter what you put in place. I have had two people write to me telling me they have found a way to stop me from stealing their images. A few minutes later, I sent them their images over e-mail. I'm not bragging, I'm simply telling you the truth. If your page or your images display on my computer, I can get them. It just isn't that hard.
  • This only works in Internet Explorer (underline for emphasis)! Netscape users can happily right click you to death.

So, if you want to use these as a first line of defense, great. Just know that they are not foolproof nor do they affect everyone. That said... we'll start with the right.


No Right Click

It's all done through the magic of JavaScript. The No Right Click script looks like this:

<SCRIPT LANGUAGE="javascript">

function click() {
if (event.button==2) {
alert('Sorry, this function is disabled.')
}
}
document.onMouseDown=click
</SCRIPT>

As you might have guessed, the event.button is the real trigger. The number "2" simply represents the right button. The alert button comes into play when the right button is clicked, negating the click altogether. Do you want to see it? Here you go:

No Right Click by order of Field Marshall Burns!


No Left Click

You can probably guess at how this one is done, but here's the script:

<SCRIPT LANGUAGE="javascript">

function click() {
if (event.button==1) {
alert('No clicking!')
}
}
document.onMouseDown=click

</SCRIPT>

New let's take a look at it.

No Left Click...or else!

(No one expects the Spanish Inquisition!)


No Clicking At All!

That means you! If you want to completely disable someone's mouse, try altering either script so that the alert will display no matter what button is pushed. It looks like this:

<SCRIPT LANGUAGE="javascript">

function click() {
if (event.button==1 || event.button==2) {
alert('No clicking!')
}
}
document.onMouseDown=click

</SCRIPT>

Want to go somewhere where you can't click at all? Enjoy.

The Land of No Clicks

(A Quinn-Martin Production)


That's That

By themselves, the scripts are not overly useful, but may be helpful for a larger effect you're trying to achieve.

Enjoy!

[No Right Click]
[No Left Click]
[No Clicking At All!]


Make a Comment

Loading Comments...

  • Web Development Newsletter Signup

    Invalid email
    You have successfuly registered to our newsletter.
  •