SHARE
Facebook X Pinterest WhatsApp

So, You Don’t Want Clicks, Huh?

Written By
thumbnail
Joe Burns
Joe Burns
Jan 4, 2005

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 <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.buttonis 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!]

Recommended for you...

The Revolutionary ES6 Rest and Spread Operators
Rob Gravelle
Aug 23, 2022
Ahead of Time (AOT) Compilation in Angular
Tariq Siddiqui
Aug 16, 2022
Converting a JavaScript Object to a String
Rob Gravelle
Aug 14, 2022
Understanding Primitive Type Coercion in JavaScript
Rob Gravelle
Jul 28, 2022
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.