Page 6
The JavaScript Document Object Model
Now that you know how to open the window of your choice, it's time to learn how to manipulate things inside that window. To really get control over the things that appear in a window, you have to learn about the JavaScript Document Object Model (DOM). And before you learn about the DOM, it helps to learn a little bit about object-oriented programming.
A Brief Overview
Object-oriented programming especially the JavaScript version of it isn't so hard to understand. The main idea is that information is organized in terms of objects. JavaScript is wonderful because it comes with a built-in library of objects. For example, a window is an object. Whenever I refer to one of the default JavaScript library objects, I will capitalize it (Window). Specific instances (a particular window) will be lowercase.
Object Properties
Objects have properties that describe them. Some of the properties of a Window object are its name, the words in its status bar, the URL of the document inside the window, and the window's document itself, which includes the words, images, and hyperlinks inside the window.
In JavaScript, you are given a default Window object called, of all things, window . One of the properties of a window is the words in its status bar. Here's how you can find out what's in the status bar of the default Window:
var the_status = window.status;
This says: "Find the status property of the Window object called window, and load it into the variable the_status." In addition to reading what those words are, you can also change them. The way to set an object's property is this:
window.status = "I'm monkeying around!";
Now let's take a look at how we can mess around with the status bar.
next page»
|