start page | rating of books | rating of authors | reviews | copyrights

Book HomeWeb Design in a NutshellSearch this book

Chapter 28. Introduction to JavaScript

Contents:

JavaScript History
JavaScript Basics
Sample Scripts
Handling Multiple Browsers

JavaScript is a client-side scripting language that adds interactivity to web pages and lets designers control various aspects of the browser itself. With JavaScript, you can do such things as display additional information about links, create mouse rollover effects, change the contents of pages based on certain conditions, randomly display content on a page, load content in new browser windows and frames, and (with some help from CSS) move elements around on the page.

A scripting language is somewhere between a markup language, like HTML, and a full-blown programming language, like Java. With JavaScript, you can add extra functionality to your web site using short snippets of scripting code that has a syntax that's fairly easy to understand.

This chapter includes material and code by Nick Heinle and Bill Peña, authors of Designing with JavaScript (O'Reilly). For a more advanced JavaScript reference, see JavaScript: The Definitive Guide by David Flanagan (O'Reilly). Also note that for simple functionality, you may not need to write your own JavaScript at all; software like Macromedia's Dreamweaver can do the coding for you, with built-in behaviors you can drop in like HTML objects. But as with HTML, if you are going to use JavaScript, you should be familiar with the basics of the language, whether you are using a WYSIWYG editor or not.

28.1. JavaScript History

JavaScript was first introduced by Netscape in Navigator 2.0, as a simple scripting language that could be embedded directly in web pages. Since then, JavaScript has evolved through five versions and is now codified in a standard. Note that the name of the language, JavaScript, is only coincidentally related to the Java programming language. Although JavaScript and Java share some similarity in syntax, you don't need to know anything about Java to learn JavaScript.

JavaScript has evolved from Version 1.0 in Navigator 2.0 to Version 1.5 in Netscape 6. Microsoft's name for its version of JavaScript is Jscript, and, for the most part, Jscript mirrors JavaScript's functionality, but also varies from version to version. At the time of this writing, the most widely supported version is 1.2, which is the basis of both Netscape's and Microsoft's 4.0 browser implementations. If you have a script that is written for an older version, say JavaScript 1.1, it will work fine with all of the newer versions. However, if you use features in a later version, say JavaScript 1.5, older browsers will not understand your scripts. Later, you'll learn how to use JavaScript to detect what browser is displaying your page, so you can customize your scripts to be backwards-compatible.

JavaScript (and Jscript) have also been standardized as ECMAScript (ECMA-262). Technically, JavaScript 1.5 is an implementation of the third version of the ECMAScript standard. Currently, both Netscape 6 and IE 5.5 support this standard version of JavaScript very well, and hopefully they will continue to agree in their support.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.