Availability: |
| |||
JavaScript syntax: | IE | mySelection = myDocument.selection | ||
Object properties: | type | |||
Object methods: | clear(), createRange(), empty() |
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.
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
type | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ReadOnly. |
Method | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
clear() | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
createRange() | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
empty() | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
Prev | Home | Next |
Select.value | Up | selection.clear() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |