Java Reference
In-Depth Information
6
Programming the Browser
Over the past few chapters, you've examined the core JavaScript language. You've seen how to
work with variables and data, perform operations on those data, make decisions in your code,
loop repeatedly over the same section of code, and even how to write your own functions. In the
preceding chapter you moved on to learn how JavaScript is an object-based language, and you
saw how to work with the native JavaScript objects. However, you are not interested only in the
language itself; you want to fi nd out how to write script for the web browser. Using this ability,
you can start to create more impressive web pages.
Not only is JavaScript object-based, but the browser is also made up of objects. When JavaScript is
running in the browser, you can access the browser's objects in exactly the same way that you
used JavaScript's native objects in the last chapter. But what kinds of objects does the browser
provide?
The browser makes available a remarkable number of objects. For example, there is a window
object corresponding to the window of the browser. You have already been using two methods of
this object, namely the alert() and prompt() methods. For simplicity, we previously referred to
these as functions, but they are in fact methods of the browser's window object.
Another object made available by the browser is the page itself, represented by the document
object. Again, you have already used methods and properties of this object. Recall from Chapter 1
that you used the document object's bgColor property to change the background color of the
page. You have also been using the write() method of the document object to write information
to the page.
A variety of other objects exist, representative of the HTML you write in the page. For example,
there is an img object for each <img/> element that you use to insert an image into your
document.
The collection of objects that the browser makes available to you for use with JavaScript is gener-
ally called the Browser Object Model (BOM) .
Search WWH ::




Custom Search