Click to See Complete Forum and Search --> : Cross browser method for getting selected text


wood_tah
08-30-2004, 09:02 AM
I am looking for a cross-browser method for obtaining the string value of user-selected text (via click and drag highlighting). Does anyone have any ideas?

I have seen an IE-only implementation using document.selection, but I am not aware of any way to get user-selected text for mozilla browsers.

gil davis
08-30-2004, 09:12 AM
Here is how it is done in Netscape:
<form>
<INPUT TYPE="BUTTON" NAME="getstring"
VALUE="Show highlighted text (if any)"
onClick="alert('You have selected:\n'+document.getSelection())">
</form>
This method was introduced in JS 1.2, so it should also work for Mozilla.

wood_tah
08-30-2004, 09:18 AM
Thanks!