O'Reilly logo

Web Design in a Nutshell by Jennifer Niederst

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 22. Introduction to JavaScript

JavaScript is a client-side scripting language that adds interactivity and conditional behavior to web pages. 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 the page.

This chapter is derived from material and code by Nick Heinle, author of Designing with JavaScript, (O’Reilly & Associates, 1997). For more tutorials on writing JavaScript, see Nick’s pages at http://webcoder.com. For a more advanced reference, see JavaScript: The Definitive Guide, Third Edition, by David Flanagan (O’Reilly & Associates, 1998). Also note that for simple functionality, you may not need to write your own JavaScript at all; software like Macromedia’s Dreamweaver can do your coding for you.

JavaScripts are usually placed directly in the HTML document. They can go either in the head or the body and there can be numerous scripts in a single HTML document. Here’s the syntax:

<SCRIPT LANGUAGE="JavaScript">
script goes here
</SCRIPT>

JavaScript Basics

There are two parts to most JavaScript applications: the functions that tell the browser what to do, and references to these functions. Let’s take the example of a simple web page that displays a linked document in a second window:

<HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required