JavaScript » Document » getSelection

Syntax:
document.getSelection( )

This method can be used to return the contents of selected text in the current document.

This method can be used to return a string containing any selected text in the current document.

Examples

Code:
<INPUT TYPE="BUTTON" NAME="selectString" VALUE="Show
any highlighted text" onClick="alert('The following text is
selected:\n'+document.getSelection());">