Selection and Range Level 2 Demonstration

Range_2_Demo.xht_source.txt XHTML 1.1 Range_2_Demo.java
[applet: unsupported by this browser]
requires: Java 1.6

The applet above uses Rhinohide to detect your text selections. For each selected range R, it inserts particulars below:

    R.getCommonAncestorContainer() =  

    R.getStartContainer() =  
       R.getStartOffset() =  
                  R.getCollapsed() =  
         R.getEndOffset() =  
      R.getEndContainer() =  

    R.toString() =
 

When collapsed, the range models a cursor (‘insertion point’ as the DOM spec calls it). You can see this by simply clicking in the text, without selecting anything.

This implementation polls once a second or so, to discover selection changes. An alternative would be to wait for a mouse or key event to signal a potential change — assuming the browser supports events.

(An interesting loop occurs if you select the entire page. Because of positive feedback in the scrollable section (R.toString, above) the selection range doubles every second. Eventually something will break... )

test host ok details
linux firefox ok
linux mozilla ok
windows firefox ok
windows ie no DOM range is unsupported by IE7.