views:

164

answers:

3

Kind of an odd question, but I have a game I am making for a Halloween party. Javascript/HTML for quick and dirty development. (This is going to be full screen on a projector and use a Wiimote for mouse control). This is what I am using, my question is not intended to invoke criticism of my code choice. It works great, except for one thing.

Basically, it is a shooting gallery/missile command style game where you need to click on or shoot objects as they move across the screen. I have onmousedown handlers for clicking on the objects. However, when you double click, i.e. fire rapidly, the object gets highlighted, as well as the other objects contained in the same div if you miss the object. To solve this, in the mousedown handler, I set focus/select a text box that is off of the page. This works to some extent, as the objects do not remain highlighted, but they do get highlighted briefly before they lose focus.

In short, is there a better way to prevent double-click from having this affect on my page?

A: 

I believe you should be able to avoid this issue by stopping the event's propagation. This should be possible to do by returning false from your mouse handlers.

Jani Hartikainen
+1  A: 

From: http://stackoverflow.com/questions/880512/prevent-text-selection-after-double-click

* {
     -moz-user-select: none; // mozilla browsers
     -khtml-user-select: none; // webkit browsers
}
Jeff B
Don't forget `user-select: none` for future compatibility.
Eli Grey
+1  A: 

In Firefox, the highlighting can be stopped simply by having the event return false. IE is a little more complicated -- you have to have the element's 'onselectstart' function return false.

noHighlightObjects[i].onselectstart = function() {
            return false;
        };
Getimoliver