This object represents a portion of the document in the current window that is currently highlighted, having been selected by the user or by a script. The selection is operated on by means of a TextRange object. This object is created by calling a createRange() method on the Selection object. This step is necessary because a selection cannot by its very nature persist very long, so a TextRange object encapsulates its value into a persistent store so it can be operated on, even though the original selection may have been deselected.
In Netscape Navigator, an entirely different technique is used that involves the document.getSelection() method.
Because it is easy to deselect the highlighted text by clicking on some other active object in the page, you will need to access the selection inside an event handler that is triggered by the selection action itself. This might be done quite effectively in an onSelectStart handler.
Selection objects do not appear to be functional on any version of MSIE for the Macintosh. This may be because the TextRange objects have not been mapped to the Macintosh cut and paste architecture.