Welcome to www.mmclean.ca!
2 Nov 2026
Summary
This article outlines how to capture right mouse clicks to help "dissuade" people taking protected images or viewing page source. This is not a 100% guarantee that data or images cannot be taken but a means of keeping "honest people honest".

Capture the Right Mouse Click

In order to try and protect valuable HTML source, JavaScript code or copyright protected images, it may be desirable to block a user from pressing the right-mouse button in order to view the source of the page or attempt to save a protected image. It would be näive to think there is a fail-safe method of protecting content published on the internet. The truth is, it is not possible. For starters, the option to "View Source" is available from a menu bar option in any web browser. In addition, pressing the right mouse button will also display an option to "View Source".

There are, however, a few things to make it more difficult for a person to obtain HTML source, JavaScript or images. The first thing would be to display the content in a window with no toolbars or menubars. This may be accomplished by opening the content in a new window using window.open and setting the following properties:

For example:
window.open("", "myWindow", "height=200,width=200,menubar=no,toolbar=no");

The second option would be to use JavaScript to capture the mouse-click event. The following is sample JavaScript code that could be embedded in any page you wish to protect. Click your right mouse button to see the script in action.

<script type="text/javascript">
var msg='Right mouse-click denied';

function _ieclick()
{
  try
  {
    if( event.button==2 ) { alert( msg ); return false; }
  }
  catch( e )
  {
    alert( 'ERROR :: _ieclick()\n\n' + e );
  }
};

function _mozclick( e )
{
  try
  {
    if( document.layers || document.getElementById && !document.all )
    {
      if( e.which==2 || e.which==3 ) 
      {
        alert( msg );
        return false;
      }
    }
  }
  catch( e )
  {
    alert( 'ERROR :: _mozclick()\n\n' + e );
  }
};

if( document.layers )
{
  document.captureEvents( Event.MOUSEDOWN );
  document.onmousedown=_mozclick;
}
else if ( document.all )
{
  document.onmousedown=_ieclick;
}

document.oncontextmenu = new Function( 'alert(msg);return false;' );
</script>
  

It should be noted that this "protection" may be bypassed with the Opera browser or any other browser that is configurable to "disallow right clicks to be received by scripts".