1

http://jsfiddle.net/JonVisc/ufHBd/4/

So in the jsFiddle the basic steps are to:

  • Click anywhere on 'Hello World' (not highlighting): Range is: true
  • Drag to highlight (highlight 'll Wor' as an example: Range is: false
  • Click anywhere in that highlighted range: Range is: false

Directly following that point the highlighting goes away, is this an event? Basically I need to detect that clearing of the highlighting (and subsequently clear a saved range since the highlighting is not there) but I unfortunately don't know how.

A click (not highlighting after that) returns the expected result of false but since I wanted that result in the previous click this isn't ideal.

1 Answers1

1

Actually the results are browser-dependent: when clicking on a non-collapsed selection in Mozilla the selection is collapsed when the click event fires but in WebKit the selection is still uncollapsed.

As to detecting it, your options are limited. Recent WebKit and IE all the way back to 5.5 fire a selectionchange event on document, which sounds like what you want:

http://jsfiddle.net/ufHBd/5/

Mozilla and Opera do not fire any useful selection-related events in regular content and all you can do is handle mouse and key events. There's a little more background in the comments to this answer: https://stackoverflow.com/a/8443541/96100

Community
  • 1
  • 1
Tim Down
  • 318,141
  • 75
  • 454
  • 536