Document.getSelection() (Method)

Return the currently selected text string.


JavaScript - 1.2
Netscape - 4.0
Property/method value type:String primitive
JavaScript syntax:NmyDocument.getSelection()

If you have selected a piece to text, in Netscape this method will return the raw unformatted text within the selection. If there are any HTML tags in the selection, they will be stripped out.

The MSIE browser employs a completely different technique that involves Selection objects and TextRange objects as a means of access to the selected text.

As 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.


See also:Document object, Document.selection, Selection object