Disable right-click menu in chrome

Viewed 41788

I'm writing aWebGL game and want to use right-click as a control. However, it throws up a menu. Is it possible to disable that? I've tried

} 
else if (event.which == 2 || event.which == 3) 
{
    doRightClickControl();
    event.preventDefault();
    event.stopPropagation();

    return false;
}

Thanks dknaack for the hint. I got it to work like this:

window.oncontextmenu = function(event) {
    event.preventDefault();
    event.stopPropagation();
    return false;
};
2 Answers

Use this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>disable rightclick menu - LabLogic</title>
</head>
<body>
<script language="javascript" type="text/javascript">
  document.oncontextmenu=RightMouseDown;
  document.onmousedown = mouseDown; 

  function mouseDown(e) {
      if (e.which==3) {//righClick
      alert("Disabled - do whatever you like here..");
   }
}
function RightMouseDown() { return false;}
</script>
</body>
</html>

Tested in chrome 17, works with other new browsers as well

Related