• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL



JavaScript. The term itself implies a scripting language, a “patchwork” for whatever Web page you have in mind. But, like many scripting languages, it's not necessarily a simple one.

What Is JavaScript?

The word “JavaScript” is really a name for a language with several different flavors. Microsoft Internet Explorer (IE) implements JavaScript under the name “JScript,” and with browser-specific code in certain areas. Netscape Navigator 4 (Nav4) interacts with Web documents quite differently than Netscape 6 (Nav6), its successor. There have been six revisions of JavaScript alone for Netscape, which invented the language. Within the next few years, JavaScript 2.0 will enter the World Wide Web.

With all these variants on the same theme, Netscape and Microsoft leave a lot of developers scrambling to write code that works in all the major browsers. Furthermore, documentation can be found from a variety of sources in various formats, some of which may be incomplete or outdated. The result is a lot of developers who cannot easily find the information for which they are looking.

A Brief History of Time (or This Project, Anyway)

This book, or at least the concept behind it, truly started in 1999, when I asked for documentation on the current Mozilla.org JavaScript Engine and Document Object Model. This was long before Netscape 6 began its beta releases and before 6.0 was released. At the time, Mr. Steve Rudman asked me if I was willing to work for him, for hire, to do the documentation on JavaScript 1.5. I refused, feeling I was not up to the task.

Eight months later, I remembered some of the words of inspiration of several professionals in life changes, notably Anthony Robbins. (Thanks, Tony, though we've never met and I've yet to attend one of your seminars. “Awaken the Giant Within” was very interesting.) Effectively, I realized I had thrown away an opportunity for which I was very competent. I replied to the newsgroup, offering my services, but it was too late.

Sams Publishing's Acquisitions department, however, watches the newsgroups as well. After numerous unspeakable delays, the result is the JavaScript Developer's Dictionary. (I've also discovered about 15 errata in the JavaScript 1.5 Core documentation I refused to do…)

In a sense, this book is for me as well as for you. You'd be surprised how much you learn about a language by writing and researching a book about it. One fact I can take pride in about this book is I could regularly turn back to earlier draft chapters in this book when I needed to build a code listing in later chapters—without going to the official references I used as starting points.

Nonetheless, in our modern age, even a book such as this is a work in progress. Therefore, before we get into the chapters themselves, I have already set up a directory on my Web site for errata, new discoveries, and so on that I, you, or other readers may discover as copies of this book get around. Visit http://www.jslab.org/jsdd for the latest details on this book and its contents.

XHTML as HTML: The Dictionary Standard

In the process of editing chapters, I made a decision to re-create each listing as XHTML 1.0 Transitional documents whenever possible. When you examine and reproduce these listings, please save them as .htm or .html files, not .xml files.

XHTML 1.0 is a “reformulation of HTML as XML,” as the W3C puts it. This means that HTML follows a very rigid structure, from which you should not deviate. Keeping to this structure gives you a solid, reproducible, and uniform DOM for each document, and subsequently each listing in this book.

However, why Transitional, and why as .htm or .html? The answer lies in the current state of affairs. Even now, we are still very much in a transition from pre-standards browsers to post-standards browsing. Internet Explorer, upon receiving an XHTML document as XML, treats it as XML and ignores the HTML features entirely. (I reference a workaround for this in Chapter 33, “Styling for HTML Elements.”) As HTML, Internet Explorer often expects closing tags when an empty element tag would be appropriate (<title></title> instead of <title />, for example).

Netscape 6 treats it as XML, running it through the XML parser, but also does not expose the full HTML DOM for the document. This is even true when you serve the document through the official XHTML mime-type, application/xhtml+xml.

For your own coding efforts, I strongly recommend you get into the habit of writing valid XHTML code as soon as possible, not only because it works in a wide variety of browsing platforms, but also because it makes your DOM much more stable and predictable. If you already know HTML (pretty much a prerequisite to this book), learning XHTML is not difficult at all. First, you learn how to write valid HTML 4.01 Transitional code (somewhat easy), and then you learn to write XHTML 1.0 Transitional code from HTML 4.01 Transitional (easy, once you get the hang of it). The HTML Validation Service at http://validator.w3.org is the only one you should trust.

What Does this Book Cover?

JavaScript Developer's Dictionary is a reference to complete and enhance the documentation for the JavaScript language. As the vast majority of Internet users use Nav4, IE4, and later generations of these two browsers, the Dictionary shall focus on JavaScript, starting primarily at this level: JavaScript 1.2 for Netscape browsers, and JScript version 3 for Internet Explorer browsers. I also cover the added and deprecated features of Internet Explorer 5.0, Internet Explorer 5.5, and Netscape 6, to JScript version 5.5 and JavaScript 1.5.

This book covers every object available to the developer in typical client-side use. It covers Core JavaScript object constructors, such as Object(), RegExp(), and Function(), in Part I.

In Part II, we enter an area of JavaScript for which there are no standards per se, but which the two browser companies mentionned previously have paralleled each other on quite closely: the window object, the navigator object, and the screen object.

Part III covers the Document Object Model for HTML documents—both within the standards defined by W3C and proprietary, non-standard definitions of each HTML element. It begins with core DOM definitions as provided by the W3C DOM for nodes, attributes, document fragments, and the like. Then the book dives into the specific properties and methods associated with each element of the HTML language. Finally, we explore events and event handlers, styling, cookies, and the DOM Level 2 Range specification.

I wrap it up in Part IV with styling several significant XML-based technologies to keep an eye on. (As you'll see, you can use JavaScript with XML documents as well.)

This book does not cover signed scripts, the security model of either browser, or server-side scripts in the JavaScript language. For the most part, these features are often far more trouble than they are worth. Signed scripts and the security model involve a fairly intimidating warning for Web site visitors, who often deny permission for what the scripts request. These areas are insignificant for most JavaScripters, and thus this book offers no emphasis on the limited features these subsets of JavaScript provide.

One feature of JavaScript I want to emphasize quite heavily at this point is the inheritance of properties and methods of some objects in other objects. For instance, every HTML element inherits the properties and methods of the HTMLElement interface, described in the HTMLElement chapter.

Likewise, the HTMLElement interface inherits properties and methods of the Element interface, which inherits properties and methods of the Node interface. I have organized the chapters of this book to present fundamental object chapters before objects inheriting their properties. For each element I note specifically what element it inherits properties and methods from. Finally, each chapter (except the Object() chapter) indicates from which object it descends.

In case you're wondering, there will be examples of each object in active use. Many times, these examples will cover innovative concepts I find extremely useful and under-used. More than that, the examples are not written for the novice JavaScripter.

This book assumes you have some familiarity with the JavaScript language, and is not intended to teach you JavaScript. The examples are just that: examples. Sometimes the examples demonstrate good coding practices, and sometimes they may be quite impractical. Nonetheless, if you are just beginning to learn JavaScript, I recommend you read Sams Teach Yourself JavaScript in 24 Hours from Sams Publishing before you read this book.

Formatting of Script Examples

Throughout the rest of this book, you will notice several conventions. Netscape Navigator 4 and Netscape 6 browsers are abbreviated Nav4 and Nav6, respectively. Internet Explorer browsers are abbreviated IE4, IE5, IE5.5, and IE6, depending on the version of browser. Other abbreviations you see frequently in this book include W3C for the World Wide Web Consortium, DOM for Document Object Model, and ECMA for ECMAScript.

In any event, you may notice indentation of code blocks:

function myFunc() {
   if (1 == 1) {
      alert("Hello World")
      } else {
      alert("Goodbye, cruel world")
   return false

The primary reason for this is visual formatting, to ensure you can follow the code examples within. The browser ignores such formatting, but it makes code far easier to read. I generally do not have anything that is not indented, except for function and object definitions belonging to the window object itself. (You'll see what I mean in Chapters 1 and 15, “Object()” and “window”.)

I introduce each feature of the language with a table indicating what browsers implement it, and in which standard, if any, a feature also belongs to: ECMAScript or the DOM. Features that are implemented in DOM Level 2 (DOM-2) but not in DOM Level 1 (DOM-1) are noted as such. Likewise, if a basic constructor or node has been deprecated, the table notes this. The primary focus of this book is on JavaScript 1.2 and JScript version 3.0 and later, but earlier versions of JavaScript receive mention as well.

All this being said, welcome to the JavaScript Developer's Dictionary. Prepare for a few surprises, and a lot of fun.

“The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own.”

–Alexander J. Vincent

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint