0

I have an application that displays text, and when the text is clicked, determines the word clicked and fires an event containing that information. The word detection is performed via JavaScript Selection - Range objects. This works perfectly in all desktop browsers, as well as the Nexus 7 and iPad. On the MS Surface however, the range returned is invalid. Where the other browsers can return a valid node for the range endpoint(s), on the surface there is only an blank space, and an offset of 0 - both of which are inaccurate.

The tools I am using:

Again, in other browsers / devices, rangy.getSelection().getRangeAt(0).inspect() returns node information and valid offsets, but on the Surface, I get nothing, just an empty inspect, similar to:

"[WrappedRange(" ":0, "":0)]"

(message not verbatim, copy pasting from the Surface being a pain)

Any ideas as to what may be going on / how I can fix it?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Clay H
  • 651
  • 9
  • 21
  • It's difficult to look into as I don't have access to a Surface. Does it work OK in all modes of IE 11 on a PC? – Tim Down Apr 25 '14 at 09:43
  • It works perfectly in IE11, as well as 10 and 9. I think it's got to be related to how the Surface handles touch events and passes them to the browser, similar to [this question](http://stackoverflow.com/questions/13130004/microsoft-surface-how-do-i-allow-javascript-touch-drag-events-to-work-without-b), but the CSS provided there did not help. – Clay H Apr 25 '14 at 13:07

1 Answers1

0

I was unable to fix the problem using the JS range, as I am for all other browsers. I had to implement a separate clicked text detection method specifically for the Surface. Thankfully, it was actually rather easy.

The Surface automatically selects the word you touch. My previous method, working with all other devices, expects an empty / collapsed selection, a cursor, and then expands from there. But for the Surface, I just have to get the selected text and clear the selection afterwards. It's actually easier - though it does mean I have to have two separate methods.

Clay H
  • 651
  • 9
  • 21