Real'sHowTo AddThis Feed Button
Custom Search

Trap the right mouse clickTag(s): Language


<HTML><HEAD>
<script language="javascript">
 function click(e) {
  if (navigator.appName == 'Netscape'
           && e.which == 3) {
      alert("no right click please")
      return false;
      }
   else {
      if (navigator.appName == 'Microsoft Internet Explorer'
          && event.button==2)
         alert("no right click please")
         return false;
         }
   return true;
 }
document.onmousedown=click
</script>
</HEAD>
<BODY>
No right mouse button here!
</BODY></HTML>
Here a way posted by A. Weslowski on the Real How-to mailng list.
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2">
var ns = (document.layers)? true:false;
var ie = (document.all)? true:false;
if (ns) document.captureEvents(Event.MOUSEDOWN || Event.CLICK);
document.onclick = sourcecodeprotect;
document.onmousedown = sourcecodeprotect;

// ***********************************************************
function sourcecodeprotect(e) {
  if (ns&&(e.which==3)) return false;
  else if (ie&&(window.event.button==2)) alert("Source code protected");
  else return true;
  }

//***********************************************************
function cleanup() {
  if (ns) document.releaseEvents(Event.MOUSEDOWN || Event.CLICK);
  }

</SCRIPT>
</HEAD>
<BODY onunload="cleanup()">
No right click here!
</BODY>
NOTE: You can still see the page source via the browser menu but you can make it a little harder by opening a new window without the menu bar or use a Frameset to display your page PLUS the above snippets to trap the RMB.

Some browsers may support a special parameter in the BODY tag to disable the RMB

<BODY oncontextmenu="return false">
To disable the Disable Mouse Dragging (Highlighting)
<BODY ondragstart="return false">
To disable the SELECT/COPY
<BODY onselectstart="return false">

blog comments powered by Disqus


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2014
[ home ]