×

Uh-oh, it looks like your Internet Explorer is out of date.

For a better shopping experience, please upgrade now.

Designing with Javascript
     

Designing with Javascript

by Nick Heinle, Richard Koman (Editor)
 

This isn't a hard-core programming book; it isn't geared toward someone who has a computer science degree from MIT and five years experience of programming in C++. This is the JavaScript book for the rest of us. Written by the author of the "JavaScript Tip of the Week" Web site, this book focuses on the most useful and applicable scripts for making truly

Overview

This isn't a hard-core programming book; it isn't geared toward someone who has a computer science degree from MIT and five years experience of programming in C++. This is the JavaScript book for the rest of us. Written by the author of the "JavaScript Tip of the Week" Web site, this book focuses on the most useful and applicable scripts for making truly interactive, engaging Web sites (and it doesn't proclaim to be the definitive all-knowing JavaScript guide).You'll not only have quick access to the scripts you need, you'll finally understand why the scripts work, how to alter the scripts to get the effects you want, and, ultimately, how to write your own groundbreaking scripts from scratch. Through his popular Web site, Nick Heinle has been showing Web designers and other nonprogrammers how to create the scripts they need. In fact, he wrote much of the JavaScript used on the Web today. This book is the culmination of his work. His explanations are clear, detailed, and accessible; everything — every script, every concept, every line — is explained so that "the rest of us" will understand.Designing with JavaScript covers many of the powerful capabilities that JavaScript is given with Dynamic HTML, in a few chapters covering important aspects of implementing Microsoft Internet Explorer 4.0 as well as Netscape Navgigator 4.0. You'll learn how to create pages on the fly, how to identify users' browsers, how to create "rollover" effects with sound, graphics, and animation, and more. It also features a CD-ROM and Web site that provide fast access to some of the author's most useful functions and scripts, making it easy to find the code you need and to build your own custom scripts.

Editorial Reviews


Fatbrain Review

Originally HTML was created for laying out and formatting text and images, but soon the Web authors realized that static pages weren't enough and the Web needed some interactivity. JavaScript gives you a break from looking at static Web pages, and allows user interaction and feedback, multimedia and animation, and it connects HTML to Java, ActiveX, and plug-ins. This book gives you a tour of different parts of JavaScript, and explains how thay can be used to create more interesting and dynamic Web sites. Find out what event handlers in JavaScript can do for you, or the document object model, providing complete control on frames, forms, and layers of content. Learn about dynamic HTML and find out what JavaScript's object model can do for you using dynamic HTML. You will also learn how to customize a site with cookies to store information over a long period of time, and how to make your site compatible with Netscape Navigator and Internet Explorer. The CD-ROM includes all the code and demos from the book, and a trial version of Infuse for Windows 95/NT. You don't need a degree in computer science to master JavaScript, and with this user-friendly guide by your side, you will be ready for advanced applications by the time you finish this book.

Booknews
Heinle, who wrote much of the JavaScript now used on the World Wide Web, offers an introduction to people who are not programmers and want to learn by doing. He explains programming principles in the context of creating scripts that make interactive and engaging web sites. Diligent readers should be able to create scripts from scratch by the time they finish the text. The CD-ROM contains all the code and demonstrations from the book and a trial version of Infuse for Windows 95/NT. No bibliography. Annotation c. by Book News, Inc., Portland, Or.
Ray Duncan

Out of the Mouth of Babes

Designing with JavaScript is not a book aimed at software developers. It's essentially a collection of application notes, illustrating how to use snippets of JavaScript to control windows, frames, buttons, menus, layers, roll-over images, and cookies. The book makes no pretense to teach programming or OOP concepts. But programmers will find its bite-sized, easy-to-digest approach to JavaScript helpful, especially those who do not have a Java or C++ background.

JavaScript books abound, and this book stands up well against its chunkier competitors, such as McComb's JavaScript SourceBook or Goodman's JavaScript Bible. The most remarkable thing about Designing with JavaScript is that the author, Nick Heinle, is reportedly only 17 years old. I'm not sure whether this says more about Heinle's abilities, the leveling influence of the World Wide Web, or the editorial talents of the people at O'Reilly.

Designing with JavaScript includes a brief reference section on the browser object hierarchy and JavaScript syntax, but purchasers of this book would be well advised to buy David Flanagan's JavaScript: The Definitive Guide (O'Reilly, 1997) as a backup and reference.--Dr. Dobb's Electronic Review of Computer Books

Product Details

ISBN-13:
9781565923003
Publisher:
O'Reilly Media, Incorporated
Publication date:
09/08/1997
Series:
Web Review Studio Series
Edition description:
Older Edition
Pages:
254
Product dimensions:
8.05(w) x 9.26(h) x 0.81(d)

Read an Excerpt


Chapter 9: Dynamic HTML

Take JavaScript's power over the page and square it; that's what you get with the capabilities of Dynamic HTML. As we've learned throughout this book, there is an object model in JavaScript (the JavaScript tree) that reflects the contents of an HTML document and allows those contents to be modified to a certain extent.

With Dynamic HTML, the object model greatly expands, encompassing almost every aspect of the page. Dynamic HTML also adds absolute positioning of HTML, a more powerful event model, and useful add-ons that allow you to play multichannel stereo sound among other things.

At the time of this book's publication, there was not yet a standard for the Dynamic HTML document object model. Because of this, the syntax discussed here is based on Microsoft's proposed object model as it appears in Internet Explorer 4. Netscape Navigator's object model, at least through version 4.0x, supports only two major aspects of Dynamic HTML: absolute positioning and a more powerful event model. Because of these differences, this chapter focuses mainly on IE's object model (which has a good chance of becoming the standard). Netscape's comparable features are described in a final section, "Netscape 4's object model," which shows how to use them.

Dynamic HTML and style sheets

Cascading style sheets and the Dynamic HTML object model are powerful partners. Style sheets give you more more control over the look and feel of your pages. Style sheets let you more accurately specify fonts, point sizes, and margin widths; they even allow you to position text and other objects at exact coordinates on the page.

We can begin to understand how style sheets, and the page in general, are accessible to JavaScript with the Dynamic HTML object model by playing around with this ordinary line of text:

I will grow.

Before we can control this text through JavaScript, we need to isolate it as an individual HTML element. This can be done by surrounding the text with a standard HTML tag, such as P, A, DIV, or SPAN, and by giving it a name with the ID attribute, which is similar to the NAME attribute. Once the text is contained within HTML tags, it becomes a malleable object that JavaScript can manipulate.


I will grow.

For example, to change the point size of this text, which we've named grow, we can access its style property (a part of all HTML elements in Dynamic HTML) and from there change its fontSize property. This is the same property that style sheets use to control font size (font-size); all of the style properties of HTML elements have style sheet counterparts. To change the size of this text to 24 points (that's right, you can specify a specific point size, not just HTMLs relative sizes), only one line of JavaScript is needed. Here we've changed the fontSize property to 24. document. all. grow. style. fontSize = 24; Obviously, fontSize is a property of style and style is a property of grow, but document. all seems a little askew. We already know that the document object is the current page, so why doesn't grow branch directly off of that? In the Dynamic HTML object model you can't use the name of the HTML element (directly) to access it through JavaScript. You must first go through the all property, which is a collection of all the elements in the body of the document. You always access your HTML elements through document. all. In truth, Internet Explorer's Dynamic HTML object model is not drastically different from what you've already learned (though there are a lot of additional objects). It is important, however, to know how to access individual HTML elements through the object model, as we've done here, because they are a vital part of Dynamic HTML. You also need to understand how to control the styles (through style sheets) of those HTML elements.

Table 9-1 lists five common style-sheet-based properties that you can modify on the fly. Remember to use the correct syntax with these properties when controlling HTML elements: document. all. elementName. style.propertyName.

Style sheets in depth

Now that you have a basic understanding of the Dynamic HTML object model in Internet Explorer, it's time to explore style sheets in greater depth. In this section we're going to create a true style sheet with styles for active links (a link is active when the mouse is placed over it) and for inactive links (the normal state of links). The inactive links will be 16-point, black text; the active links will be underlined, 18-point, blue text. After we've created these styles, we'll use JavaScript to apply them interactively through the Dynamic HTML object model. Figure 9-1 shows what this page looks like when a user places the mouse over one of the links.

We'll begin by creating a style sheet with styles named on and off. These will contain the text styles for the active and inactive links. Figure 9-2 shows the HTML for this page....

Meet the Author

Nick Heinle is perhaps the Web's best known resource for JavaScript. His JavaScript tips are used by many of the leading Web sites, including sites for "Star Wars," CNN, Digital Equipment, IBM, and Prentice Hall. He will graduate Needham High School in 1998.

Customer Reviews

Average Review:

Post to your social network

     

Most Helpful Customer Reviews

See all customer reviews