Working with Browser-Based Objects

[ LiB ]

Working with Browser-Based Objects

When an HTML page loads a browser such as Netscape Communicator or Internet Explorer, the browser defines a collection of objects based on the content it finds on the page. These objects are created in a top-down order as the page is loaded. As the browser builds the object references, it does so in a hierarchical fashion.

The object organizational hierarchy for a given browser is known as its object model . In the early days of Internet browser development, there were many differences in the object models provided by various browsers. In addition, as companies such as Microsoft and Netscape improved their browsers over the years , they continued to add new features and support for new objects. As a result, JavaScripts that were designed to be processed by the latest version of either of these two browsers often didn't work with older browsers, which even today are still used by many people. Even worse , you couldn't count on your JavaScripts running the same way when executed by Internet Explorer or Netscape Communicator. All this made for a very confusing situation.

Because of the number of different versions of Internet Explorer and Netscape Communicator that have been developed over the years, there is no way that I can cover issues specific to each version of both browsers within the confines of this book. There are just too many different objects, and these objects have too many methods and properties to be covered in a single weekend . Therefore, I plan to cover the objects that you'll most likely need to work with. In addition, the scripts provided in this book will be written and tested using the latest versions of Internet Explorer and Netscape Communicator.

A Browser View of Objects

When a browser loads an HTML page, it simultaneously creates a logical view of all relevant objects into a tree-like structure. These objects are related to one another and have parent-child and sibling relationships. For example, consider the following HTML page:

 <HTML>   <HEAD>     <TITLE>Script 3.1 - A Typical HTML page</TITLE>   </HEAD>    <BODY>     <P>Hello.</P>     <P>Welcome to my Web site.</P>   </BODY> </HTML> 

When loaded by a browser, you see the output shown in Figure 3.1.

Figure 3.1. From a browser point of view, the content displayed in this Web page consists of objects that are related to one another.


The browser, on the other hand, sees the content of the HTML page a little differently, as depicted in Figure 3.2.

Figure 3.2. Examining the organizational tree structure of objects located on an HTML page


As you can see, the document object resides at the top of this tree. Underneath it are the various HTML tags that define its contents, and under these tasks is the content they contain.

[ LiB ]

Learn JavaScript In a Weekend
Learn JavaScript In a Weekend, Second Edition
ISBN: 159200086X
EAN: 2147483647
Year: 2003
Pages: 84 © 2008-2017.
If you may any questions please contact us: