Question

I am working on an RTS game where you can select units and right click to make them go somewhere. You can also shift right click to queue up a list of points you would like the units to travel to.

In all browsers except FF this is working perfectly.

In Firefox however the shift right click triggers a context menu (right click without shift does not). I am handling the contextmenu event and calling preventDefault but that doesn't seem to do anything in FF when the shift button is held.

Is there any way to block this behavior in FF?

My game is here: https://mod.it/4plhXo3l and the code in question in in the RTSBoard.js file on line 36.

Was it helpful?

Solution

I managed to get this working in Firefox by setting event.shiftKey to false, then calling preventDefault(), and stopPropagation(), then returning false. I then set the document model's onclick event and ondblclick events to the same function you wound up using for yourself, plus the added setting of the shiftkey to false. I also had to do this for mouseup events, because clicking and dragging was also causing context menus to pop up.

I'm not sure it can be fully 100% disabled, but this looks to be about the closest you can get it.

OTHER TIPS

Answering my own question. It appears that calling preventDefault and stopPropagation in the document.onclick event solves the issue.

See this reddit thread for more discussion: http://www.reddit.com/r/javascript/comments/1agoj8/is_it_possible_to_block_the_shift_right_click/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top