I'm capturing mouse events on a web page, specifically onclick. When I click in two different locations, my code is doing something at those two locations. But after the second click (with event.shiftKey=true), I also am finding that the contents of the page between those two locations are being selected as if I had done a click-drag-release between the start and end points.
I have looked at a couple of questions [1] and [2]regarding not allowing text to be selected, but both of those answers deal with CSS, which is inappropriate for this situation, both because the elements involved are arbitrary and of varying quantities, and because I don't want to disable showing a selection (I want to show a selection if there is one!), I want to disable from actually getting a selection at a specific time. So, clearing any selection that might have "accidentally" be made is out of the question too, as this would get rid of any previous valid selection.
I was thinking that the event is somehow propagating into the native code where it is making the selection, so I tried:
event.cancelBubble = true
event.preventDefault()
return false
But this did not work. I have only tested this with Chrome, but cross-browser is best.
Update: I have created a single Fiddle to demonstrate the problem. Click on any line of text in the output. Then shift+click on any other line. Both lines will have the CSS applied but there is also a light-blue browser selection in place, which I am trying to prevent.
Update 2: I'm voting to close because is @ivy_lynx pointed out, it is really a duplicate, and the answer at this linked question solves the problem.