Main Page

JavaScript in the Browser

JavaScript in the Browser
In the preceding chapters, you learned about JavaScript’s core, ECMAScript, and how the basics of
the language work. Beginning with this chapter, the focus switches to using JavaScript inside its
natural habitat: the Web browser.
Web browsers have come a long way since JavaScript was first introduced in Netscape Navigator
2.0. Browsers today are capable of handling a variety of file formats, not just conventional HTML.
Ironically enough, JavaScript is used in most of these file formats as a way to dynamically change
content on the client. This chapter explores how JavaScript fits into HTML and other languages, as
well as introduces you to some basic concepts of the Browser Object Model (BOM).
JavaScript in HTML
Of course, it was HTML that first made use of embedded JavaScript, so the natural first discussion
point is how JavaScript is used in HTML. The evolution of HTML to include JavaScript began with
the introduction of tags to be used in conjunction with JavaScript, as well as the addition of new
attributes for several common parts of HTML.
The <script/> tag
JavaScript is included in HTML pages by using the
tag. Typically located within the
tag of a page, the
tag was originally defined to have one or two attributes:
that indicates the scripting language being used and, optionally,
that indicates
an external JavaScript file to include in the page. The
attribute is traditionally set
, but it can also be used to indicate the exact version of JavaScript, such as
(if the
attribute is omitted, the browser defaults to the most current
version of JavaScript available).
08_579088 ch05.qxd 3/28/05 11:37 AM Page 125

JavaScript EditorFree JavaScript Editor     Ajax Editor