• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

right mouse button

How do we program the right mouse button? on asp.net pages?
0
goodk
Asked:
goodk
  • 2
  • 2
1 Solution
 
jorge_torizResearch & Development ManagerCommented:
I use this function to block the right click, you can use it as a template for your implementation
<script language="javascript" type="text/javascript">
  var message="Your copy right message";
  function clickIE()
  {
    if (document.all)
    {
      alert(message);
      return false;
    }
  }
  function clickNS(e)
  {
    if (document.layers || (document.getElementById && !document.all))
    {
      if (e.which==2||e.which==3)
      {
        alert(message);
        return false;
      }
    }
  }
  if (document.layers)
  {
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS;
  }
  else
  {
    document.onmouseup=clickNS;
    document.oncontextmenu=clickIE;
  }
  function rightClick()
  {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf("msie") != -1)
    alert(message);

    return false;
  }
  document.oncontextmenu=new Function("return rightClick();
</script>

Open in new window

0
 
goodkAuthor Commented:
thanks for your help, I am getting error on your last line
 document.oncontextmenu=new Function("return rightClick();

0
 
jorge_torizResearch & Development ManagerCommented:
Sorry:

document.oncontextmenu=new Function("return rightClick()");
0
 
goodkAuthor Commented:
very timely and correct! thanks
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now