516 Dynamic HTML: Object Model and Collections Chapter 15

15 Dynamic HTML: Object Model and Collections 1 2 3 4 5 6 7 8 Object Model 9 10 17 18 19 20 21 22

Welcome to our Web page!

23 24 25 Fig. 15.1 Object referencing with the Dynamic HTML Object Model (part 1 of 2).

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. Chapter 15 Dynamic HTML: Object Model and Collections 517

Fig. 15.1 Object referencing with the Dynamic HTML Object Model (part 2 of 2).

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. 518 Dynamic HTML: Object Model and Collections Chapter 15

1 2 3 4 5 6 7 8 Object Model 9 10 21 22 23 24 25

Elements on this Web page:

26 27 28

Fig. 15.2 Looping through the all collection .

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. Chapter 15 Dynamic HTML: Object Model and Collections 519

1 2 3 4 5 6 7 8 Object Model 9 10 31 32 33 35 36

Welcome to our Web page!

37 38

39 Elements on this Web page: 40

41 42 43

Fig. 15.3 Navigating the object hierarchy using collection children (part 1 of 2).

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. 520 Dynamic HTML: Object Model and Collections Chapter 15

Fig. 15.3 Navigating the object hierarchy using collection children (part 2 of 2).

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. Chapter 15 Dynamic HTML: Object Model and Collections 521

1 2 3 4 5 6 7 8 Object Model 9 10 18 19 20 21 22

Welcome to our Web site!

23 24 25 Fig. 15.4 Dynamic styles (part 1 of 2).

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. 522 Dynamic HTML: Object Model and Collections Chapter 15

Fig. 15.4 Dynamic styles (part 2 of 2).

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. Chapter 15 Dynamic HTML: Object Model and Collections 523

1 2 3 4 5 6 7 8 Object Model 9 10 18 19 27 28 29 30 31

Welcome to our Web site!

32 33 34

Fig. 15.5 Dynamic styles in action (part 1 of 2).

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. 524 Dynamic HTML: Object Model and Collections Chapter 15

Fig. 15.5 Dynamic styles in action (part 2 of 2).

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. Chapter 15 Dynamic HTML: Object Model and Collections 525

1 2 3 4 5 6 7 8 Dynamic Positioning 9 10 45 46 47 48 49

51 Welcome!

52 Fig. 15.6 Dynamic positioning (part 1 of 2).

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. 526 Dynamic HTML: Object Model and Collections Chapter 15

53 54

Fig. 15.6 Dynamic positioning (part 2 of 2).

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. Chapter 15 Dynamic HTML: Object Model and Collections 527

1 2 3 4 5 6 7 8 Frames collection 9 10 11 12 13 14 15 16

Fig. 15.7 FRAMESET file for cross-frame scripting.

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. 528 Dynamic HTML: Object Model and Collections Chapter 15

17 18 19 20 21 22 23 24 The frames collection 25 26 34 35 36 37 38

Cross-frame scripting!

39 40 41 42

Fig. 15.8 Accessing other frames.

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. Chapter 15 Dynamic HTML: Object Model and Collections 529

1 2 3 4 5 6 7 8 The navigator Object 9 10 24 25 26 27 28

Redirecting your browser to the appropriate page, 29 please wait...

30 31 32

Fig. 15.9 Using the navigator object to redirect users.

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. 530 Dynamic HTML: Object Model and Collections Chapter 15

window

document all

frames document anchors

history document applets

navigator body plugins location embeds

event filters

screen forms

images

Key links

object plugins

collection scripts

styleSheets

Fig. 15.10 The DHTML Object Model.

Object or collection Description

Objects window This object represents the browser window and provides access to the document object contained in the window. If the window contains frames, a separate window object is created automatically for each frame, to provide access to the document rendered in that frame. Frames are considered to be subwindows in the browser. document This object represents the HTML document rendered in a window. The document object provides access to every element in the HTML docu- ment and allows dynamic modification of the HTML document. body This object provides access to the BODY element of an HTML document.

Fig. 15.11 Objects in the object model (part 1 of 3). © Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. Chapter 15 Dynamic HTML: Object Model and Collections 531

Object or collection Description

history This object keeps track of the sites visited by the browser user. The object provides a script programmer with the ability to move forward and back- ward through the visited sites, but for security reasons does not allow the actual site URLs to be manipulated. navigator This object contains information about the Web browser, such as the name of the browser, the version of the browser, the operating system on which the browser is running and other information that can help a script writer customize the user’s browsing experience. location This object contains the URL of the rendered document. When this object is set to a new URL, the browser immediately switches (navigates) to the new location. event This object can be used in an event handler to obtain information about the event that occurred (e.g., the mouse coordinates during a mouse event). screen The object contains information about the computer screen for the com- puter on which the browser is running. Information such as the width and height of the screen in pixels can be used to determine the size at which elements should be rendered in a Web page.

Collections all Many objects have an all collection that provides access to every ele- ment contained in the object. For example, the body object’s all col- lection provides access to every element in the BODY element of an HTML document.

anchors This collection contains all anchor elements (A) that have a NAME or ID attribute. The elements appear in the collection in the order they were defined in the HTML document. applets This collection contains all the APPLET elements in the HTML docu- ment. Currently, the most common APPLET elements are Java™ applets. embeds This collection contains all the EMBED elements in the HTML document. forms This collection contains all the FORM elements in the HTML document. The elements appear in the collection in the order they were defined in the HTML document. frames This collection contains window objects that represent each frame in the browser window. Each frame is treated as its own subwindow. images This collection contains all the IMG elements in the HTML document. The elements appear in the collection in the order they were defined in the HTML document. links This collection contains all the anchor elements (A) with an HREF prop- erty. This collection also contains all the AREA elements that represent links in an image map.

Fig. 15.11 Objects in the Internet Explorer 5 object model (part 2 of 3).

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook. 532 Dynamic HTML: Object Model and Collections Chapter 15

Object or collection Description

plugins Like the embeds collection, this collection contains all the EMBED ele- ments in the HTML document. scripts This collection contains all the SCRIPT elements in the HTML docu- ment. styleSheets This collection contains styleSheet objects that represent each STYLE element in the HTML document and each style sheet included in the HTML document via LINK.

Fig. 15.11 Objects in the Internet Explorer 5 object model (part 3 of 3).

15.1

© Copyright 2000 by Prentice Hall. All Rights Reserved. For use only by instructors in classes for which Java How to Program, Third Edition is the required textbook.