SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 1916 | Next

Joseph W. Lowery

"Dreamweaver CS3 Bible"

To examine what is contained within the byte offsets returned by the
getSelection() function, you use the offsetsToNode() function, explained later in this section.
The dom.setSelection() function
Just as getSelection() retrieves the memory offsets of the current selection, the setSelection()
function sets a new pair of memory offsets and thus a new selection. The setSelection() function takes
two arguments: offsetBegin and offsetEnd.
setSelection() is most often used to restore a user??™s selection after various document manipulations
have taken place. In this example, the selection is first stored in a variable via getSelection() and then,
after much document modification, restored by setSelection:
var currSelection = theDOM.getSelection();
// document altering code goes here
theDom.setSelection(currSelection[0],currSelection[1]);
If the new setting does not conform to a valid HTML selection, such as the attributes within a
tag, the selection expands to include the entire tag.
You can also use setSelection to deselect anything on the page after completing a behavior. All that??™s
required is that the two arguments be equal. Using the preceding example, this code
theDOM.setSelection(currSelection[1],currSelection[1]);
places the cursor after the previous selection, whereas
theDOM.


Pages:
1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928