Contents Manipulation
Dynamic HTML exposes the following three techniques for manipulating
the contents of a document. The first technique is used to generate contents
while a page is loading, and the other two techniques are used to manipulate
the document after the page has finished loading.
- Writing contents into the stream during the loading of a page
- Manipulating the contents using properties and methods
exposed on all elements in the body of the document
- Programming the TextRange object, which exposes an object
model for the document's text
The first technique uses the write and writeln methods of the document object. These methods can insert contents into the current document as it is being downloaded, and they can construct new documents, but they cannot change contents that have already been parsed. Chapter 6, "The HTML Document," discussed the document's write methods. The write and writeln methods are supported in Netscape Navigator version 2.0 and later and Microsoft Internet Explorer 3.0.
The latter two techniques constitute dynamic contents and are new
with Internet Explorer 4.0. All elements in the document's body provide direct
access to the contained contents of any element by using four properties and
two methods. This chapter introduces these members, which are the simplest
way of accessing and changing the contents of the document.
The TextRange object exposes a custom text-based object model that
provides arbitrary access to the underlying contents, giving you more control
over the document at the expense of predictability. This technique allows you
to manipulate contents as you would using a text editor. While many
manipulations are possible through the text-based model, it is not as precise as
a true top-down tree approach and has a number of limitations. Chapter 14, "User Selection and Editing Operations," reviews the
TextRange object model's strengths and weaknesses. [Содержание]
|