|
|
|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98
CHAPTER 26 Advanced Microsoft Dynamic HTML
by Jim O'Donnell
- In this chapter
- Microsofts Implementation of Dynamic HTML 638
- Internet Explorer Document Object Model 638
- Dynamic HTML Events and the event Object 646
- Using Dynamic HTML with Styles 650
- Dynamic HTML and the Data Source Object 652
- Position HTML Elements with Dynamic HTML 655
- Changing HTML Documents On-the-Fly 658
- Dynamic HTML Filters 660
- Microsofts Scriptlets 665
- Find Out More About Dynamic HTML 667
Microsofts Implementation of Dynamic HTML
Dynamic HTML is Microsofts term for the new technology it has embedded in its Internet Explorer Web browser, versions 4 and higher. Through Dynamic HTML, you can create Web pages that can change dynamically and have a much higher degree of interaction than in the past. The heart of Dynamic HTML is Microsofts new Document Object Model. This model is what provides you, and scripts that you write, with the capability to interact with and change any element in an HTML document.
This chapter shows some examples of the kinds of things you can do with Dynamic HTML (and related technologies, such as Scriptlets). None of the examples shown represents anything you could not have done in the pastnow, however, it is possible to do them using HTML alone. Dynamic HTML is a new technology still under development. People are just scratching the surface of what is possible with it. This chapter identifies some of the best places to look for examples and more information.
Internet Explorer Document Object Model
The heart of Dynamic HTML is the new Document Object Model that Internet Explorer supports. You can think of every element in an HTML document as an objectincluding the HTML tags and information that they containas well as aspects of the Web browser itself and any included Java applets, ActiveX Controls, or other elements. The Document Object Model is what exposes these objects, making them accessible to you through scripts that you can write and include with the document.
Before Internet Explorer 4 and Dynamic HTML, the Document Object Model was very limited. It could expose Java applets, ActiveX Controls, and the Web browser window properties, such as window size and location. The model exposed a very limited number of HTML elements, however. The HTML tags that were supported by past object models were primarily limited to HTML Forms elements.
Microsofts Dynamic HTML changes all that. With Dynamic HTML, every HTML tag is exposed through the Document Object Model. Not only that, but the contents of all HTML container tags are also exposed. Therefore, not only can you change the styles or formats associated with a <P> tag, for instance, but you can also change its text contents. And, this is all done on the client side, without any need to interact with the Web server.
The remainder of this section discusses aspects of the Document Object Model for Internet Explorer 4. It is important to at least understand the different terms used with the object modelobject, property, method, collection, and event and what they mean. This section gives you a good basis for understanding the Dynamic HTML samples later in the chapter.
NOTE: For the remainder of this chapter, references to Internet Explorer should be interpreted to mean Internet Explorer version 4 and higher (unless otherwise noted). Although Internet Explorer version 5 may support the W3C Document Object Model standard if the standard is available before version 5 is finalized, the browser will probably be backward compatible with the version 4 object model.
Understanding Objects and the Object Hierarchy
Figure 26.1 shows the hierarchy of objects that is part of the Internet Explorer Document Object Model. In the simplest terms, an object in this model is a recognizable element of the whole. Objects can contain other objects, however; thus, all the objects are organized into an object hierarchy.
FIGURE 26.1 The preceding boxed elements of the Document Object Model represent the additions that Dynamic HTML uses.
As you look at Figure 26.1, the window object, at the top of the hierarchy, includes everything you see within a given Web browser window. That object can and will, in turn, contain other objects. This object hierarchy is used when referencing these objects, with the following sample notation:
window.document.links[0]
This line of code refers to the first link object contained in the current document of a given Web browser window. (Normally, unless you are authoring Web pages that use multiple windows, you can omit window.)
A description of each type of object in the Internet Explorer Document Object Model follows:
- windowRepresents an open Web browser window.
- locationInformation for the current URL.
- framesA collection of window objects, one for each separate frame in the current window.
- historyInformation for the recently visited URLs.
- navigatorInformation about the browser itself.
- eventMaintains the state of events occurring within the browser.
- screenStatistics on the physical screen and the rendering capabilities of the client.
- documentContains all the information attached to the current HTML document.
- linksA collection of links referenced in the current document.
- anchorsA collection of anchors present within the current document.
- formsCan contain a number of other objects corresponding to the forms elements within it; there is one forms object for each HTML form in the document.
- appletsContains information about the Java applets present.
- embedsHas information about all objects included using the <EMBED> tag; this object can also be referenced using the synonym plugins.
- scriptsA collection of all the script elements within the document.
- imagesA collection that contains one element for each image in the document.
- filtersContains a collection of the filter objects associated with the document.
- allAllows access to all the HTML tags that are a part of the document.
- selectionRepresents the current active selection, a user-selected block of text within the document.
- styleSheetsA collection of the style sheets attached to the current document.
- bodyAccesses the <BODY> section of the document.
|