Home / code

Prevent right- and left-click

Writer: Christophe Wolfs
Published: 27 March 2008

This is a small script that prevents right- and left clicking.
Note : They still can see your source code through VIEW->SOURCE.
The bad part of this script is that you can't click any links.

<script language="JavaScript"><!--
//stops both right- and left-click function
//downloaded from webmaster2020.com

function right(mousebutton)
{
  var msg1 = "Hey!! Look but don't touch!";
  var msg2 = "Don't click here either!";

  if (navigator.appName == 'Netscape' && mousebutton.which==3)
  {
        alert(msg1);
        return false;
  }
  else
  if (navigator.appName == 'Netscape' && mousebutton.which==1)
  {
        alert(msg2);
        return false;
  }
  else
  if (navigator.appName == 'Microsoft Internet Explorer' && event.button == 1)
  {
        alert(msg1);
        return false;
  }
  else
  if (navigator.appName == 'Microsoft Internet Explorer' && event.button == 2)
  {
        alert(msg2);
        return false;
  }
  return true;
}
document.onmousedown = right;
//--></script>

 

TOP