I'm making a game, it uses the canvas element, and I need both of the mouse buttons. How can I stop the browser (I'd like it to run in most major ones, so, it's preferred that the solution is universal) from opening that dialogue box when the user presses the right mouse button. How can I do that in JavaScript? I tried this, but it does not work:
self.onClick = function(ev)
{
if(ev.button == 2)
{
ev.preventDefault();
}
var x = ev.clientX - self.canvas.offsetLeft;
var y = ev.clientY - self.canvas.offsetTop;
input.mouse = {"button": ev.button, "click": true, "x": x, "y": y};
}
The global variable input is then sent to the server to be processed.
EDIT: it works now. I had to edit the canvas element (canvas oncontextmenu="return false")