|
October 22, 2001 Selecting Text in Netscape 6 Tips: October 2001
Yehuda Shiran, Ph.D.
|
|
Netscpae 6 features the getSelection() method of the document object. This method returns a string containing the text of the current selection. Its general syntax is:
The following example demonstrates the getSelection() method:
The script displays the current selection in a box. At first, it instructs the browser to capture all mouseup events. As explained in Column 9, Column 10, and Column 11, this is only required for Navigator 4.0x, so a simple object detection routine makes sure the browser is Netscape 6 before executing the statement.
The event processing function first assigns the selection's text to a variable named The statement:
terminates the function if the user is running a browser that doesn't support the document object's getSelection() method. Therefore, no error is generated on Internet Explorer 4.0x or older browsers.
People who read this tip also read these tips: Look for similar tips by subject: |