homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

No Right Click HTML
What is the correct HTML to use to disable right click?

 11:10 pm on Jun 14, 2006 (gmt 0)

I would like to know what is the correct html to use to disable the right click on my site. I do not want anyone to view source or copy my work or images.

I've searched for this online, however, have not found anything useful or conclusive.

Thank you in advance for your help.



 11:16 pm on Jun 14, 2006 (gmt 0)

Try a search for "javascript disable right click".



 8:34 am on Jun 15, 2006 (gmt 0)

The trouble with this approach is that it doesn't work. There's no way to stop anyone from taking your images if they really want to, as the images are still sent out to the browser. Best thing in my experience to do is to watermark them and leave it at that.

As for stopping them from viewing the page source, if you disable the right click (which is easily disabled in browsers like Firefox) then they can click View / Page Source and still get access to it.


 1:46 pm on Jun 15, 2006 (gmt 0)

You could use a program like "html protector" to scramble your source code, but could effect search engine rankings for that page.


 9:23 pm on Jun 15, 2006 (gmt 0)

html source is generally not looked upon as "secret". PHP files or code-behind classes are already protected by the engines that output them. HTML however, is quite a basic language and generally people dont steal html from others (as its just presentation layer). Disabling the right mouse button will help, but as stated earler there really is no way to protect the html.



 10:01 pm on Jun 15, 2006 (gmt 0)

The down side is that people are prevented from using other right click functions such as opening a link in a new tab/window which actually keeps them on your site.

Images can be copied in seconds even if you have a no right click script. As a demonstration (with the owners permission) I once "stole" an image from a "protected" page and opened it in a graphics viewer. Opening the image took longer than acquiring it!


 1:08 pm on Jun 16, 2006 (gmt 0)

We might want to sticky one of the more productive threads that have already discussed this... can't remember the one I posted in, but:

Two things to think about, Wolflover:

1. There's no reason I can think of to protect pure HTML. There's nothing you've done in HTML that hasn't been done already, or couldn't be guessed at by an experienced designer. As someone else mentioned, programming pages like php would be a more noble thing to protect... HTML is too easy and too widespread for protection of it to make any sense. I'm sure most of us could guess what your HTML looks like just by viewing your site, no offense.

2. There are two kinds of people stealing your images: people who like your work and want to make it a pretty wallpaper on their computer(which does virtually no harm to you, and could even help promote your site), and people who want to illegally pass off your images as their own. The former group MIGHT be inexperienced enough to be thwarted by a "no right click" or "no source view" technique, but as I said, they're not the problem, so why piss off those people? The latter group- the image pirates- WILL get your image. There's nothing you can do about it. There are several very simple ways to get an image that don't even relate to right-clicking... I myself often prefer to take a screenshot instead of right-clicking, regardless of whether someone has attempted to protect it. You can't protect your images as it stands today.

The best way to keep your images safe is to make them look as bad as possible, as stupid as that sounds (and is). Make them very small, plaster your domain name over top of them, etc. You have to actually alter the image in question.


 3:25 pm on Jun 17, 2006 (gmt 0)

The others are right about HTML, there's no way (or reason) to "protect" it.

Regarding images, one commonly-used tactic is to use CSS to position a transparent .gif "over" the image you want to protect. People right-click what they think is your image, save it, and find they have this transparent .gif instead. However, this is a clumsy way to work, and is still only marginally effective. Anyone who knows the first thing about the web could get the image in just a few seconds. Even failing in that, there's always a screenshot, which you can't prevent.

Best thing to do about it is just get used to the idea that, as far as images go, people can get it if you put it on the web. By putting an image online, you give up all possible expectations of retaining control over how it is used or by whom. Of course there would always be the possibility of suing people who infringe on copyrights, but that's expensive and rarely pays off.


 11:18 am on Jun 20, 2006 (gmt 0)

You can't stop screenshots so images can always be stolen.

But what I found once on a site where i was 'borrowing' an image myself was that they had cut the image into 10px blocks so the image itself was made out of 200 or so blocks. That did stop me from using right click to copy.

However this makes for so much extra code en trouble that it's not worth your effort either.

If it's a specific image someone could buy or use and harm you in the process (revenues) put a watermark on it, but other than that, there'snothing you can do.


 7:46 am on Jun 26, 2006 (gmt 0)

You can't stop screenshots so images can always be stolen

Ya can't stop image theft, but you sure can stop screenshots:

<body oncontextmenu="return false">

This will fill the clip board so nothing else can be added. Rather a dirty trick though and will certainly piss off the user - but then again, that user just tried to steal from you :)

Note: this code is not standards compliant.


 8:15 am on Jun 26, 2006 (gmt 0)

<body oncontextmenu="return false">

Just a note that this stops right-clicking but has no bearing upon the clipboard (as incorrectly stated above). It's also a very very annoying thing to do as the context menu is used for many tools other than copying your code.

Top Tip
Firefox users can ensure they can always right-click, without having to disable javascript. Do this as follows:
Edit > Preferences > Content > Enable Javascript [click Advanced]
Untick the box for 'disable or replace context menus'


 7:13 pm on Jun 26, 2006 (gmt 0)

Thanks for the correction vincevincevince.


 9:36 pm on Jun 26, 2006 (gmt 0)

>> Just a note that this stops right-clicking but
>> has no bearing upon the clipboard (as
>> incorrectly stated above).

And also certainly does nothing to prevent screenshots (as also is incorrectly stated above).


 5:39 am on Jun 27, 2006 (gmt 0)

Geez - alright already.

I had originally posted both codes, then decided to remove the clipboard method but deleted the wrong explantion without checking.

Your pencils come without erasers do they?


 6:25 am on Jun 27, 2006 (gmt 0)

This is one of those topics that always seems to stir the emotions. The answer to WolfLover's original question is that you can indeed use JavaScript to disable the right click. And it WILL work for SOME visitors. We've all seen it on web sites. Therefore, it may not hurt to go ahead and do it (as long as you know that it also prevents the user from doing anything else that's on the right click menu).

As others have said, just don't think that it will absolutely prevent people from stealing images or viewing HTML source. But for those users who only know how to use the right click, it will work fine. Might be a small percentage, but what the heck.

Here's a good one:



 8:49 pm on Jun 27, 2006 (gmt 0)

The ability to swipe your images is only a PRT SCRN away.


 9:05 pm on Jun 27, 2006 (gmt 0)

>> I had originally posted both codes, then
>> decided to remove the clipboard method but
>> deleted the wrong explantion without checking.

Sorry, not meaning to ride you for a simple error, but at the same time we're trying to leave a thread containing accurate information. Followup posts making corrections shouldn't be taken personally, but while our pencils do come with erasers this thread doesn't -- so clear statements that earlier information was erroneous will be helpful to anyone who comes across this later.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved