Javascript problem in Firefox - disable right click

Please bear in mind I am a novice - EXTREME novice so I may be asking a very simple, stupid question. If so forgive me.

I have what I think is a simple script that I use on my website to disable the use of right click to copy images etc. It works in IE but not Firefox.
Here is the script

var message=“Thank you for visiting my site.

Copying text and images is disabled on this page to protect Copyright.

However if you want permission to use text or images please email me.

This Site Copyright ©2011.”;
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
return false;
if (document.layers) {
if (e.which == 3) {
return false;
if (document.layers) {

I have read somewhere that the document.all and document.layers do not work in Firefox. If this is the case how so I achieve this in Firefox.

That code is aimed at IE4 and Netscape 4 browsers - it doesn’t contain anything for more modern browsers that no longer use document.all and document.layers. It will work in some but not all of the more recent versions of IE but only if the browser security is set incorrectly.

About ten years ago the ability to disable anything in the browser from JavaScript was been removed and control given to the owner of the browser. If they want to disable parts of the scripts you add to your page then they can but you can’t disable any of the functionality of their browser without their permission.

This script will work unless disabled by user option.

It has the advantage of working only when images are right-clicked, otherwise allowing the context menu.

<script type='text/javascript'>

 (function( imgStr  ) /** No right click ON IMAGES ONLY **/
   function installHandler( obj, evt, func )
     window.attachEvent ? obj.attachEvent( 'on' + evt, func ) : obj.addEventListener( evt, func, false );

   function noImg( e /*2843294C6F676963416C69*/ )
     if( /^(IMG|AREA)$/.test( ( || e.srcElement ).nodeName ) )
        if( imgStr )
          alert( imgStr );

        e.preventDefault ? e.preventDefault() : e.returnValue = false;

   installHandler( document, 'contextmenu', noImg );

 })( "To use images, please ask owner\\'s permission." );  /** <-- Place your warning message between quotes or to display no message, leave as "" **/


Thank you very much! This works great.
Does anyone know how I can stop the text being copied as well?
I’ve had half my site ripped of by someone else and as I put a lot of effort into developing it I don’t want someone else doing the same thing again.
I know that you can override it in the browser settings but at least it’s will stop the none savvy!

It will definitely encourage those with a slight knowledge of how their browser works to steal your content just because they think that they are clever because they know how to bypass those trivial blocks. If they actually reduced the amount of theft then the major sites would implement that type of code but if anything it has the opposite effect.

Thanks for your help - will look at maybe buying some software to protect my source.
One I’ve found is HTMLGuard. Do you know if this is ok or is there a better one?

Personally I wouldn’t bother with HTMLGuard, it’s quite easy to bypass the code obfuscation they use just by downloading the supposedly encrypted page “Sample” I was able to view it and do copy-and-paste by just editing two characters making it totally useless.

I can override any image blocking by merely tapping my PrtScn button, which captures the screen as an image, then opening it up in Photoshop and cropping it. These right-click scripts don’t work for those who really want to get the image.

You can’t stop someone from going to your page in the browser and hitting Edit > Copy, and copying the entire page to their hard drive, then opening that page in Notepad or TextEdit and editing it.

Nowadays you can even highlight a PDF and copy the text, so PDF isn’t the answer, either.

The problem is that programs that will undo everything that programs like that one do to try to “protect” your page are easy to obtain - they are available as free downloads from many different web sites - they are called “web browsers”.

See for a series of articles I have written about web page protection. You can get all the various “protection” that is available from there at no charge (where some of the other equivalents will cost you several hundred dollars). You will also find there the much easier to implement scripts that will bypass all the “protection” of ALL programs that produce content that can be displayed in a web browser. So if you must annoy your legitimate visitors by implementing useless protection at least you will not have spent any money on it.

Thanks Steve - looks like I have some bedtime reading to do!
As a newby - you may well end up getting lots of questions though!!! :frowning: