1. Trang chủ
  2. » Giáo án - Bài giảng

hungry minds javascript bible 4th ed

2.3K 11.4K 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • JavaScript ™ Bible 4th Edition

    • Front matter

      • Praise for Danny Goodman s

      • About the Author

      • Credits

      • Foreword

      • Preface

        • Organization and Features of This Edition

          • Part I

          • Part II

          • Part III

          • Part IV

          • Part V

          • Part VI

          • CD-ROM

        • Prerequisites to Learning JavaScript

          • If you ve never programmed before

          • If you ve done a little programming before

          • If you ve programmed in C before

          • If you ve programmed in Java before

          • If you ve written scripts (or macros) before

        • Formatting and Naming Conventions

      • Acknowledgments

      • Contents at a Glance

      • Contents

      • Getting Started with JavaScript

    • Getting Started with JavaScript

      • JavaScript s Role in the World Wide Web and Beyond

        • Competition on the Web

        • Hypertext Markup Language (HTML)

        • CGI Scripting

        • Of Helpers and Plug-ins

        • Java Applets

        • JavaScript: A Language for All

          • LiveScript becomes JavaScript

          • The Microsoft world

        • JavaScript: The Right Tool for the Right Job

      • Authoring Challenges Amid the Browser Wars

        • Leapfrog

        • Duck and Cover

        • Compatibility Issues Today

          • Separating language from objects

          • Core language standard

          • Document object model

          • Cascading Style Sheets

          • Dynamic HTML

        • Developing a Scripting Strategy

      • Your First JavaScript Script

        • The Software Tools

          • Choosing a text editor

          • Choosing a browser

        • Setting up Your Authoring Environment

          • Windows

          • MacOS

          • Reloading issues

        • What Your First Script Will Do

        • Entering Your First Script

        • Examining the Script

          • The <SCRIPT> tag

          • A script for all browsers

          • Displaying some text

        • Have Some Fun

    • JavaScript Tutorial

      • Browser and Document Objects

        • Scripts Run the Show

        • JavaScript in Action

          • Interactive user interfaces

          • Small data lookup

          • Forms validation

          • Interactive data

          • Multiple frames

          • Dynamic HTML

          • When to use JavaScript

        • The Document Object Model

          • Containment hierarchy

        • When a Document Loads

          • A simple document

          • Add a form

          • Add a text input element

          • Add a button element

        • Object References

          • Object naming

          • A simple document

          • Add a form

          • Add a text input element

          • Add a button element

        • About the Dot Syntax

          • Newsgroup organization model

        • What Defines an Object?

          • Properties

          • Methods

          • Event handlers

        • Exercises

      • Scripts and HTML Documents

        • Where Scripts Go in Documents

          • The <SCRIPT> tag

          • Tag positions

          • Handling older browsers

        • JavaScript Statements

        • When Script Statements Execute

          • While a document loads immediate execution

          • Deferred scripts

        • Viewing Script Errors

        • Scripting versus Programming

        • Exercises

      • Programming Fundamentals, Part I

        • What Language Is This?

        • Working with Information

        • Variables

          • Creating a variable

          • Variable names

        • Expressions and Evaluation

          • Expressions in script1.htm

          • Expressions and variables

        • Data Type Conversions

          • Converting strings to numbers

          • Converting numbers to strings

        • Operators

          • Arithmetic operators

          • Comparison operators

        • Exercises

      • Programming Fundamentals, Part I I

        • Decisions and Loops

        • Control Structures

          • if constructions

          • if . . . else constructions

        • About Repeat Loops

        • Functions

          • Function parameters

          • Variable scope

        • About Curly Braces

        • Arrays

          • Creating an array

          • Accessing array data

          • Parallel arrays

          • Document objects in arrays

        • Exercises

      • Window and Document Objects

        • Document Objects

        • The Window Object

          • Accessing window properties and methods

          • Creating a window

        • Window Properties and Methods

          • window.status property

          • window.alert() method

          • window.confirm() method

          • window.prompt() method

          • onLoad event handler

        • The Location Object

        • The History Object

        • The Document Object

          • document.forms[ ] property

          • document.title property

          • document.write() method

        • The Link Object

        • Exercises

      • Forms and Form Elements

        • The FORM Object

          • Form as object and container

          • Accessing form properties

          • form.elements[ ] property

        • Form Controls as Objects

          • Text-related objects

        • The Button Object

        • The Checkbox Object

        • The Radio Object

        • The SELECT Object

        • Passing Form Data and Elements to Functions

        • Submitting and Prevalidating Forms

        • Exercises

      • Strings, Math, and Dates

        • Core Language Objects

        • String Objects

          • Joining strings

          • String methods

        • The Math Object

        • The Date Object

        • Date Calculations

        • Exercises

      • Scripting Frames and Multiple Windows

        • Frames: Parents and Children

        • References among Family Members

          • Parent-to-child references

          • Child-to-parent references

          • Child-to-child references

        • Frame Scripting Tips

        • Controlling Multiple Frames Navigation Bars

        • More about Window References

        • Exercises

      • Images and Dynamic HTML

        • The Image Object

          • Interchangeable images

          • Precaching images

          • Creating image rollovers

        • More Dynamism in HTML

        • Exercises

    • Document Objects Reference

      • JavaScript Essentials

        • JavaScript Versions

        • Core Language Standard ECMAScript

        • Embedding Scripts in HTML Documents

          • <SCRIPT> tags

          • Hiding script statements from older browsers

          • Hiding scripts entirely?

          • Script libraries (.js files)

          • Library compatibility issues

          • Navigator 3&4 JavaScript entities

        • Browser Version Detection

          • Is JavaScript on?

          • Scripting for different browsers

        • Designing for Compatibility

          • Dealing with beta browsers

          • The Evaluator Sr.

          • Compatibility ratings in reference chapters

        • Language Essentials for Experienced Programmers

        • Onward to Object Models

      • Document Object Model Essentials

        • The Object Model Hierarchy

          • Hierarchy as road map

          • The browser document object road map

        • How Document Objects Are Born

        • Object Properties

        • Object Methods

        • Object Event Handlers

          • Event handlers as methods

          • Event handlers as properties

        • Object Model Smorgasbord

        • Basic Object Model

        • Basic Object Model Plus Images

        • Navigator 4-Only Extensions

          • Event Capture Model

          • Layers

        • Internet Explorer 4+ Extensions

          • HTML element objects

          • Element containment hierarchy

          • Cascading Style Sheets

          • Event bubbling

          • Event binding of scripts

          • Win32 features

        • Internet Explorer 5+ Extensions

        • The W3C DOM

          • DOM levels

          • What stays the same

          • What isn t available

          • New HTML practices

          • New DOM concepts

          • Static W3C DOM HTML objects

          • Bidirectional event model

        • Mixing Object Models

          • The conservative approach

          • Middle ground

          • A radical approach

          • Handling events

        • Simulating IE4+ Syntax in NN6

          • The

          • property simulator

          • The content properties simulators

        • Where to Go from Here

      • Generic HTML Element Objects

        • Generic Objects

          • Syntax

          • About these objects

          • Properties

          • Methods

          • Event handlers

          • Common keyboard event tasks

      • Window and Frame Objects

        • Window Terminology

        • Frames

          • Creating frames

          • The frame object model

          • Referencing frames

          • Top versus parent

          • Preventing framing

          • Ensuring framing

          • Switching from frames to frameless

          • Inheritance versus containment

          • Frame synchronization

          • Blank frames

          • Viewing frame source code

          • Frames versus FRAME element objects

        • Window Object

          • Syntax

          • About this object

          • Properties

          • Methods

          • Event handlers

        • FRAME Element Object

          • Syntax

          • About this object

          • Properties

        • FRAMESET Element Object

          • Syntax

          • About this object

          • Properties

        • IFRAME Element Object

          • Syntax

          • About this object

          • Properties

        • popup Object

          • Syntax

          • About this object

          • Properties

          • Methods

      • Location and History Objects

        • Location Object

          • Syntax

          • About this object

          • Properties

          • Methods

        • History Object

          • Syntax

          • About this object

          • Properties

          • Methods

      • The Document and Body Objects

        • Document Object

          • Syntax

          • About this object

          • Properties

          • Methods

          • Event handlers

        • BODY Element Object

          • Syntax

          • About this object

          • Properties

          • Methods

          • Event handlers

      • Body Text Objects

        • BLOCKQUOTE and Q Element Objects

          • Syntax

          • About these objects

          • Property

        • BR Element Object

          • Syntax

          • About this object

          • Property

        • FONT Element Object

          • Syntax

          • About this object

          • Properties

        • H1 . . . H6 Element Objects

          • Syntax

          • About these objects

          • Property

        • HR Element Object

          • Syntax

          • About this object

          • Properties

        • LABEL Element Object

          • Syntax

          • About this object

          • Properties

        • MARQUEE Element Object

          • Syntax

          • About this object

          • Properties

        • Methods

        • Event Handlers

          • About this object

        • Range Object

          • Syntax

          • Working with ranges

          • Properties

          • Methods

        • selection Object

          • Syntax

          • About this object

          • Properties

          • Methods

        • Text and TextNode Objects

          • Syntax

          • About this object

          • Properties

          • Methods

        • TextRange Object

          • Syntax

          • About this object

          • Working with text ranges

          • About browser compatibility

          • Properties

          • Methods

        • TextRectangle Object

          • Syntax

          • About this object

          • Properties

      • HTML Directive Objects

        • HTML Element Object

          • Syntax

          • About this object

          • Property

        • HEAD Element Object

          • Syntax

          • About this object

          • Properties

        • BASE Element Object

          • Syntax

          • About this object

          • Properties

        • BASEFONT Element Object

          • Syntax

          • About this object

          • Properties

        • ISINDEX Element Object

          • Syntax

          • About this object

        • LINK Element Object

          • Syntax

          • About this object

          • Properties

          • Event handlers

        • META Element Object

          • Syntax

          • About this object

          • Properties

        • SCRIPT Element Object

          • Syntax

          • About this object

          • Properties

        • TITLE Element Object

          • Syntax

          • About this object

          • Property

      • Link and Anchor Objects

        • Anchor, Link, and A Element Objects

          • Syntax

          • About this object

          • Properties

      • Image, Area, and Map Objects

        • Image and IMG Element Objects

          • Syntax

          • About this object

          • Properties

          • Event handlers

        • AREA Element Object

          • Syntax

          • About this object

          • Properties

        • MAP Element Object

          • Syntax

          • About this object

          • Properties

      • The Form and Related Objects

        • The Form in the Object Hierarchy

        • FORM Object

          • Syntax

          • About this object

          • References to form control elements

          • Passing forms and elements to functions

          • E-mailing forms

          • Changing form attributes

          • Buttons in forms

          • Redirection after submission

          • Form element arrays

          • About <INPUT> element objects

          • Properties

          • Methods

          • Event handlers

        • FIELDSET and LEGEND Element Objects

          • Syntax

          • About these objects

        • LABEL Element Object

          • Syntax

          • About this object

          • Properties

      • Button Objects

        • The BUTTON Element Object, and the Button, Submit, and Reset Input Objects

          • Syntax

          • About these objects

          • Properties

          • Methods

          • Event handlers

        • Checkbox Input Object

          • Syntax

          • About this object

          • Properties

          • Methods

          • Event handlers

        • Radio Input Object

          • Syntax

          • About this object

          • Properties

          • Methods

          • Event handlers

        • Image Input Object

          • Syntax

          • About this object

          • Properties

      • Text-Related Form Objects

        • Text Input Object

          • Syntax

          • About this object

          • Text fields and events

          • Text field values and persistence

          • Properties

          • Methods

          • Event handlers

        • Password Input Object

          • Syntax

          • About this object

        • Hidden Input Object

          • Syntax

          • About this object

        • TEXTAREA Element Object

          • Syntax

          • About this object

          • Carriage returns inside textareas

          • Properties

          • Methods

      • Select, Option, and FileUpload Objects

        • SELECT Element Object

          • Syntax

          • About this object

          • Modifying SELECT options (NN3+, IE4+)

          • Modifying SELECT options (IE4+)

          • Modifying SELECT options (W3C DOM)

          • Properties

          • Methods

          • Event handlers

        • OPTION Element Object

          • Syntax

          • About this object

          • Properties

        • OPTGROUP Element Object

          • Syntax

          • About this object

          • Properties

        • File Input Element Object

          • Syntax

          • About this object

      • Table and List Objects

        • The Table Object Family Hierarchy

          • Populating table cells

          • Modifying table cell content

          • Modifying table rows

          • Modifying table columns

          • W3C DOM table object classes

        • TABLE Element Object

          • Syntax

          • About this object

          • Properties

          • Methods

        • TBODY, TFOOT, and THEAD Element Objects

          • Syntax

          • About these objects

          • Properties

        • CAPTION Element Object

          • Syntax

          • About this object

        • COL and COLGROUP Element Objects

          • Syntax

          • About these objects

          • Properties

        • TR Element Object

          • Syntax

          • About this object

          • Properties

          • Methods

        • TD and TH Element Objects

          • Syntax

          • About these objects

          • Properties

        • OL Element Object

          • Syntax

          • About this object

          • Properties

        • UL Element Object

          • Syntax

          • About this object

          • Properties

        • LI Element Object

          • Syntax

          • About this object

          • Properties

        • DL, DT, and DD Element Objects

          • Syntax

          • About these objects

        • DIR and MENU Element Objects

          • Syntax

          • About these objects

      • The Navigator and Other Environment Objects

        • clientInformation Object (IE4+) and navigator Object ( All)

          • Syntax

          • About this object

          • Properties

          • Using the appVersion property

          • userAgent property details

          • Methods

        • mimeType Object

          • Syntax

          • About this object

          • Properties

        • plugin Object

          • Syntax

          • About this object

          • Properties

          • Methods

        • Looking for MIME Types and Plug-ins

          • Overview: using mimeType and plugin objects

          • Verifying a MIME type

          • Verifying a plug-in

          • Verifying both plug-in and MIME type

          • Managing manual plug-in installation

          • Plug-in detection in IE/ /Windows

        • screen Object

          • Syntax

          • About this object

          • Properties

        • userProfile Object

          • Syntax

          • About this object

          • Methods

      • Event Objects

        • Why Events ?

          • What an event knows (and when it knows it)

          • The static Event object

        • Event Propagation

          • NN4 event propagation

          • IE4+ event propagation

          • NN6+ event propagation

        • Referencing the event object

          • IE4+ event object references

          • NN4+ (W3C) event object references

        • event Object Compatibility

        • Dueling Event Models

          • Cross-platform modifier key check

          • Cross-platform key capture

        • Event Types

          • Older browsers

          • Event types in IE4+ and NN6

        • NN4 event Object

          • Syntax

          • About this object

          • Properties

        • IE4+ event Object

          • Syntax

          • About this object

          • Properties

        • NN6+ event Object

          • Syntax

          • About this object

          • Properties

          • Methods

      • Style Sheet and Style Objects

        • Making Sense of the Object Names

        • Imported Style Sheets

        • Reading Style Properties

        • STYLE Element Object

          • Syntax

          • About this object

          • Properties

        • styleSheet Object

          • Syntax

          • About this object

          • Properties

          • Methods

        • cssRule and rule Objects

          • Syntax

          • About these objects

          • Properties

        • currentStyle , runtimeStyle , and style Objects

          • Syntax

          • About these objects

          • Style properties

          • Property values

          • Text and font properties

          • Inline display and layout properties

          • Positioning properties

          • Background properties

          • Border and edge properties

          • List Properties

          • Scrollbar properties

          • Table properties

          • Page and printing properties

          • Miscellaneous properties

          • Aural properties

        • filter Object

          • Syntax

          • About this object

          • IE5.5 filter syntax changes

      • Positioned Objects Summary

        • What Is a Layer?

      • Positioned Objects

        • What Is a Layer?

        • NN4 Layer Object

          • Syntax

          • About this object

          • Layer references

          • Layers and forms

          • Layers and tables

          • Properties

          • Methods

          • Event handlers

        • Positioned Elements in the Modern DOM

          • Changing element backgrounds

          • Layer clipping

          • Scripting nested layers

          • Loading external HTML into a layer

          • Positioned element visibility behavior

          • Scripting layer stacking order

          • Dragging and resizing a layer

      • Embedded Objects

        • APPLET Element Object

          • Syntax

          • About this object

          • Properties

        • OBJECT Element Object

          • Syntax

          • About this object

          • Properties

        • EMBED Element Object

          • Syntax

          • About this object

          • Properties

        • The Odd Case of the PARAM Element

      • XML Objects

        • Elements and Nodes

        • XML Element Object

          • Syntax

          • About this object

          • Properties

    • JavaScript Core Language Reference

      • The String Object

        • String and Number Data Types

          • Simple strings

          • Building long string variables

          • Joining string literals and variables

          • Special inline characters

        • String Object

          • Syntax

          • About this object

          • Properties

          • Parsing methods

        • String Utility Functions

          • Formatting methods

        • URL String Encoding and Decoding

      • The Math, Number, and Boolean Objects

        • Numbers in JavaScript

          • Integers and floating-point numbers

          • Hexadecimal and octal integers

          • Converting strings to numbers

          • Converting numbers to strings

          • When a number isn t a number

        • Math Object

          • Syntax

          • About this object

          • Properties

          • Methods

          • Creating random numbers

          • Math object shortcut

        • Number Object

          • Syntax

          • About this object

          • Properties

          • Methods

        • Boolean Object

          • Syntax

          • About this object

      • The Date Object

        • Time Zones and GMT

        • The Date Object

          • Creating a date object

          • Native object properties and methods

          • Date methods

          • Accommodating time zones

          • Dates as strings

          • Friendly date formats for older browsers

          • More conversions

          • Date and time arithmetic

          • Counting the days. . .

          • Date bugs and gremlins

        • Validating Date Entries in Forms

      • The Array Object

        • Structured Data

        • Creating an Empty Array

        • Populating an Array

        • JavaScript 1.2 Array Creation Enhancements

        • Deleting Array Entries

        • Parallel Arrays

        • Multidimensional Arrays

        • Array Object Properties

        • Array Object Methods

      • The Regular Expression and RegExp Objects

        • Regular Expressions and Patterns

        • Language Basics

          • Simple patterns

          • Special characters

          • Grouping and backreferencing

        • Object Relationships

        • Using Regular Expressions

          • Is there a match?

          • Getting information about a match

          • String replacement

        • Regular Expression Object

          • Syntax

          • About this object

          • Properties

          • Methods

        • RegExp Object

          • Syntax

          • About this object

          • Properties

      • Control Structures and Exception Handling

        • If and If. . .Else Decisions

          • Simple decisions

          • About (

          • ) expressions

          • Complex decisions

          • Nesting if. . .else statements

        • Conditional Expressions

        • Repeat (for) Loops

          • Putting the loop counter to work

          • Breaking out of a loop

          • Directing loop traffic with continue

        • The while Loop

        • The do-while Loop

        • Looping through Properties (for-in)

        • The with Statement

        • Labeled Statements

        • The switch Statement

        • Exception Handling

          • Exceptions and errors

          • The exception mechanism

        • Using try-catch-finally constructions

          • Real-life exceptions

        • Throwing Exceptions

        • Error Object

          • Syntax

          • About this object

          • Properties

          • Methods

      • JavaScript Operators

        • Operator Categories

        • Comparison Operators

        • Equality of Disparate Data Types

        • Connubial Operators

        • Assignment Operators

        • Boolean Operators

          • Boolean math

          • Boolean operators at work

        • Bitwise Operators

        • Object Operators

        • Miscellaneous Operators

        • Operator Precedence

      • Functions and Custom Objects

        • Function Object

          • Syntax

          • About this object

          • Creating functions

          • Nesting functions

          • Function parameters

          • Properties

          • Methods

        • Function Application Notes

          • Invoking Functions

          • Variable Scope: Globals and Locals

          • Parameter variables

          • Recursion in functions

          • Turning functions into libraries

        • Custom Objects

          • An example planetary objects

          • Creating an array of objects

          • Adding a custom method

          • More ways to create objects

          • Object watcher methods

          • Defining object property getters and setters

          • Using custom objects

        • Object-Oriented Concepts

          • Adding a prototype

          • Prototype inheritance

          • Nested objects and prototype inheritance

        • Object Object

          • Syntax

          • About this object

          • Methods

      • Global Functions and Statements

        • Functions

        • Statements

    • Preview

    • Appendixes

      • JavaScript and Browser Object Quick Reference

      • JavaScript Reserved Words

      • Answers to Tutorial Exercises

        • Chapter 4 Answers

        • Chapter 5 Answers

        • Chapter 6 Answers

        • Chapter 7 Answers

        • Chapter 8 Answers

        • Chapter 9 Answers

        • Chapter 10 Answers

        • Chapter 11 Answers

        • Chapter 12 Answers

      • JavaScript and DOM Internet Resources

        • Support and Updates for this Book

        • Newsgroups

        • FAQs

        • Online Documentation

        • World Wide Web

      • What s on the CD- ROM

        • System Requirements

        • Disc Contents

          • JavaScript listings for Windows and Macintosh text editors

          • JavaScript and Browser Object Quick Reference from Appendix A ( Adobe Acrobat format)

          • Adobe Acrobat Reader

          • Reference examples from Parts III and IV

          • Searchable version of the book

          • Commercial software products

          • Commercial, trial, and shareware software

      • Examples from Parts III and IV

        • Chapter 15 Examples

        • Generic Objects

          • Properties

          • Methods

          • Event handlers

        • Chapter 16 Examples

        • Window Object

          • Properties

          • Methods

          • Event handlers

        • FRAME Element Object

          • Properties

        • FRAMESET Element Object

          • Properties

        • IFRAME Element Object

          • Properties

        • popup Object

          • Properties

          • Methods

        • Chapter 17 Examples

        • Location Object

          • Properties

          • Methods

        • History Object

          • Properties

          • Methods

        • Chapter 18 Examples

        • Document Object

          • Properties

          • Methods

          • Event Handlers

        • BODY Element Object

          • Properties

          • Methods

          • Event Handlers

        • Chapter 19 Examples

        • FONT Element Object

          • Properties

        • HR Element Object

          • Properties

        • MARQUEE Element Object

          • Properties

        • Methods

        • Range Object

          • Properties

          • Methods

        • selection Object

          • Properties

          • Methods

        • Text and TextNode Objects

          • Properties

          • Methods

        • TextRange Object

          • Properties

          • Methods

        • TextRectangle Object

          • Properties

        • Chapter 22 Examples

        • Image and IMG Element Objects

          • Properties

          • Event handlers

        • AREA Element Object

          • Properties

        • MAP Element Object

          • Property

        • Chapter 23 Examples

        • FORM Object

          • Properties

          • Methods

          • Event handlers

        • LABEL Element Object

          • Property

        • Chapter 24 Examples

        • The BUTTON Element Object and the Button, Submit, and Reset Input Objects

          • Properties

          • Methods

          • Event handlers

        • Checkbox Input Object

          • Properties

          • Event handlers

        • Radio Input Object

          • Properties

          • Event handlers

        • Chapter 25 Examples

        • Text Input Object

          • Properties

          • Methods

          • Event handlers

        • TEXTAREA Element Object

          • Properties

          • Methods

        • Chapter 26 Examples

        • SELECT Element Object

          • Properties

          • Methods

          • Event handlers

        • OPTION Element Object

          • Properties

        • OPTGROUP Element Object

          • Properties

        • Chapter 27 Examples

        • TABLE Element Object

          • Properties

          • Methods

        • TBODY, TFOOT, and THEAD Element Objects

          • Properties

        • COL and COLGROUP Element Objects

          • Properties

        • TR Element Object

          • Properties

        • TD and TH Element Objects

          • Properties

        • OL Element Object

          • Properties

        • UL Element Object

          • Properties

        • LI Element Object

          • Properties

        • Chapter 28 Examples

        • clientInformation Object (IE4+) and navigator Object ( All)

          • Properties

          • Methods

        • screen Object

          • Properties

        • userProfile Object

          • Methods

        • Chapter 29 Examples

        • NN4 event Object

          • Properties

        • IE4+ event Object

          • Properties

        • NN6+ event Object

        • Chapter 30 Examples

        • styleSheet Object

          • Properties

          • Methods

        • cssRule and rule Objects

          • Properties

        • Chapter 31 Examples

        • NN4 Layer Object

          • Properties

          • Methods

        • Chapter 34 Examples

        • String Object

          • Properties

          • Parsing methods

        • Chapter 35 Examples

        • Number Object

          • Properties

          • Methods

        • Chapter 37 Examples

        • Array Object Methods

        • Hungry Minds, Inc. End- User License Agreement

  • JavaScript Bible Bonus Gold Chapters 43-57

    • Data-Entry Validation

      • Real- Time versus Batch Validation

        • Real-time validation triggers

          • Listing 43-1: Allowing Only Numbers into a Text Box

        • Batch mode validation

      • Designing Filters

      • Building a Library of Filter Functions

        • isEmpty()

          • Listing 43-2: Is an Entry Empty or Null?

        • isPosInteger()

          • Listing 43-3: Test for Positive Integers

        • isInteger()

          • Listing 43-4: Checking for Leading Minus Sign

        • isNumber()

          • Listing 43-5: Testing for a Decimal Point

        • Custom validation functions

          • Listing 43-6: A Custom Validation Function

      • Combining Validation Functions

        • Listing 43-7: Master Validation Function

      • Date and Time Validation

        • Listing 43-8: Simple Date Validation

        • Listing 43- 8:

      • Selecting Text Fields for Reentry

      • An Industrial-Strength Validation Solution

        • Structure

        • Dispatch mechanism

          • Listing 43-9: Creating the Dispatch Lookup Table

          • Listing 43-10: Main Validation Function

        • Sample validations

          • U.S. state name

          • Listing 43-11: Creating a U.S. States Array

          • Listing 43-11:

          • Listing 43-12: Validation Function for U.S. States

          • Date validation

          • Listing 43-13: Date Range Validations

          • Listing 43-14: Primary Date Validation Function

          • Listing 43-15: Functions to Check Month Lengths

          • Cross-confirmation fields

          • Listing 43-16: Cross-Confirmation Validation

          • Listing 43-16:

        • Last-minute check

        • Try it out

          • Listing 43-17: Frameset for Trying validation.js

      • Plan for Data Validation

    • Scripting Java Applets and Plug- ins

      • LiveConnect Overview

      • Why Control Java Applets?

      • A Little Java

        • Java building blocks classes

        • Java methods

          • Listing 44-1: Stopping and Starting an Applet

        • Java applet properties

        • Accessing Java fields

      • Scripting Applets in Real Life

        • Getting to scriptable methods

          • Listing 44-2: Partial Listing for ScriptableClock.java

          • Listing 44-3: A More Fully Scripted Clock

          • Listing 44-3:

        • Applet limitations

        • Faceless applets

          • Listing 44-4: Java Applet Source Code

          • Listing 44-5: HTML Asking Applet to Read Text File

        • Data type conversions

      • Applet-to-Script Communication

        • What your applet needs

        • What your HTML needs

        • About JSObject class

          • Table 44-1 JSObject Class Methods

        • Data type conversions

        • Example applet-to-script application

          • Listing 44-6: Java Applet Source Code

          • Listing 44-6 (continued): Java Applet Source Code

          • Listing 44-7: HTML Document Called by Applet

      • Scripting Plug-ins

        • The HTML side

          • Using EMBED

          • IE/Windows OBJECT

          • Using EMBED and OBJECT together

          • Validating the plug-in

        • The API approach

          • Loading the library

          • Initializing the library

          • Sound player API objects

          • Plug-in checking

          • Listing 44-8: setType() and Supporting Functions from DGAudioAPI. js

          • Listing 44-8:

          • Invoking methods

          • Extending the library

        • Building a jukebox

          • Listing 44-9: A Scripted Jukebox

          • Listing 44-9:

        • Embedding multiple sounds

          • Listing 44-10: Scripting Multiple Sounds

          • Listing 44-10:

      • Scripting Java Classes Directly

    • Debugging Scripts

      • Syntax versus Runtime Errors

      • Error Message Notification

        • Netscape console windows

        • Multiple error messages

      • Error Message Details

        • Error file name

        • Error location

        • Error message text

          • ÏObject expectedÓ

          • ÏExpected <something>Ó

          • Ï<Something> is undefinedÓ

          • Ï<Something> is not a functionÓ

          • ÏObject doesnÌt support this property or methodÓ

          • ÏUnterminated string literalÓ

          • ÏUnterminated string constantÓ

          • ÏMissing } after function bodyÓ

          • ÏExpected }Ó

          • Ï<Something> is not a numberÓ

          • Ï<Something> has no property named . . .Ó

          • Ï<Something> has no propertiesÓ

          • Ï<Something> is null or not an objectÓ

          • Ï<Something> has no property indexed by [i]Ó

          • Ï<Something> canÌt be set by assignmentÓ

          • ÏTest for equality (==) mistyped as assignment (=)? Assuming equality test.Ó

          • ÏFunction does not always return a valueÓ

          • ÏAccess disallowed from scripts at <URL> to documents at <URL>Ó

          • ÏAccess is deniedÓ

          • ÏLengthy JavaScript still running. Continue?Ó

          • ÏUnspecified errorÓ

          • ÏUncaught exceptionÓ

          • ÏToo many JavaScript errorsÓ

      • Sniffing Out Problems

        • Check the HTML tags

        • View the source

        • Intermittent scripts

        • Scripts not working in tables

        • Timing problems

        • Reopen the file

        • Find out what works

        • Comment out statements

        • Check runtime expression evaluation

        • Using the embeddable Evaluator

        • Emergency evaluation

      • A Simple Trace Utility

        • The trace() function

          • Listing 45-1: trace() function

        • Preparing documents for trace.js

        • Invoking trace()

          • Listing 45-2: Calling trace()

      • Browser Crashes

      • Preventing Problems

        • Getting structure right

        • Build incrementally

        • Test expression evaluation

        • Build function workbenches

      • Testing Your Masterpiece

    • Security and Netscape Signed Scripts

      • Battening Down the Hatches

      • When Worlds Collide

      • The Java Sandbox

      • Security Policies

      • The Same Origin Policy

        • Setting the document.domain

        • Origin checks

          • Window object checks

          • Location object checks

          • Document object checks

          • NN4 layer object checks

          • Form object checks

          • Applet object checks

          • Image object checks

          • Linked script library checks

      • The Netscape Signed Script Policy

        • Signed objects and scripts

        • What you get with signed scripts

      • The Digital Certificate

        • How to get a certificate

        • Activating the codebase principal

      • Signing Scripts

        • Signing tool

        • Preparing scripts for signing

        • The ARCHIVE attribute

        • The ID attribute

          • Listing 46-1: Basic Signed Script Structure

        • Editing and moving signed scripts

      • Accessing Protected Properties and Methods

        • Gaining privileges

        • Specifying a target

          • Table 46-1 Scripting-Related Privilege Targets

      • Blending Privileges into Scripts

        • Keep the window small

        • Think of the users

      • Example

        • Accessing a protected window property

          • Listing 46-2: Creating an alwaysRaised Window

      • Handling Privilege Manager Errors

      • Signed Script Miscellany

        • Exporting and importing signed scripts

        • Locking down your signed pages

        • International characters

    • Cross-Browser Dynamic HTML Issues

      • What Is DHTML?

      • Striving for Compatibility

      • Working Around Incompatibilities

        • Old-fashioned compatibility tricks

          • Inline branching

          • Platform equivalency

        • Modern approaches to compatibility

          • Object detection

          • Listing 47-1: Using Object Detection to Assemble an Element Object Reference

          • Custom APIs

        • Handling non-DHTML browsers

      • A DHTML API Example

        • UNKNOWN

          • Listing 47-2: The Custom API (DHTMLapi.js)

    • Internet Explorer Behaviors

      • Style Sheets for Scripts

      • Embedding Behavior Components

        • Linking in a behavior component

        • Enabling and disabling behaviors

      • Component Structure

        • Script statements

        • Variable scope

        • Assigning event handlers

        • Exposing properties and methods

      • Behavior Examples

        • Example 1: Element dragging behavior

          • Listing 48-1: An Element Dragging Behavior

          • Listing 48-2: Three Draggable Elements Using the Behavior

        • Example 2: Text rollover behavior

          • Listing 48-3: Rollover Behavior (makeHot.htc)

          • Listing 48-4: Applying the Rollover Behavior

      • For More Information

    • Application: Tables and Calendars

      • About the Calendars

      • Static Tables

        • Listing 49-1: A Static Table Generated by JavaScript

        • Listing 49- 1:

      • Dynamic Tables

        • Listing 49-2: A Dynamic Calendar Table

        • Listing 49-2:

      • Hybrids

      • Dynamic HTML Tables

        • Listing 49-3: Dynamic HTML Calendar

        • Listing 49-3:

      • Further Thoughts

    • Application: A Lookup Table

      • A Serverless Database

      • The Database

      • The Implementation Plan

      • The Code

      • Further Thoughts

    • Application: A "Poor Man's" Order Form

      • Defining the Task

      • The Form Design

      • Form HTML and Scripting

        • Global adjustments

        • Do the math

        • Cooking up some HTML

        • Some JavaScript language cleanup

        • Tedium lost

        • Tedium regained

      • Further Thoughts

    • Application: Outline- Style Table of Contents

      • Design Challenges

      • The Implementation Plan

      • The Code

        • Setting the frames

        • Outline code

        • Assembling outline content

        • Cookie storage

        • The focal point

        • Selecting a widget image for an entry

        • Initialize the cookie

        • Writing the outline

        • Customization possibilities

          • Alternative displays

          • Cookie-free zones

          • Expanding/collapsing all at once

          • Reducing server access

          • Multiple outlines

      • Cascading Style Sheet Version

        • CSS implementation plan

        • The CSS code

      • A Futuristic (XML) Outline

        • Birth of an XML specification

        • OPML outliner prep

        • The XML and HTML code

        • Setting the scripted stage

        • Accumulating the HTML

        • Toggling node expansion

        • Wrap up

      • Further Thoughts

    • Application: Calculations and Graphics

      • The Calculation

      • User Interface Ideas

      • The Code

        • Basic arrays

        • Calculations and formatting

        • Preloading images

        • Changing images on the fly

        • Creating the SELECT objects

        • Drawing the initial images

      • Further Thoughts

    • Application: Intelligent "Updated" Flags

      • The Cookie Conundrum

      • TimeÌs Not on Your Side

      • The Application

      • The Code

        • Setting the stage

        • The date comparison

        • A live <BODY>

      • Further Thoughts

    • Application: Decision Helper

      • The Application

      • The Design

      • The Files

        • Table 55-1 Files Comprising the Decision Helper Application

      • The Code

        • index.htm

        • dhNav.htm

        • dh1.htm

        • dh2.htm

        • dh3.htm

        • dh4.htm

        • dh5.htm

        • dhHelp.htm

      • Further Thoughts

    • Application: Cross- Browser DHTML Map Puzzle

      • The Puzzle Design

      • Implementation Details

        • The custom API

        • The main program

          • Listing 56-1: The Main Program (mapgame.htm)

      • Lessons Learned

    • Application: Transforming XML Data Islands

      • Application Overview

      • Implementation Plan

      • The Code

        • Style sheets

        • Initialization sequence

        • Converting the data

        • Sorting the JavaScript database

        • Constructing the table

        • SELECT controls

      • Dreams of Other Views

      • What About NN6?

Nội dung

Praise for Danny Goodman’s JavaScriptBible “JavaScript TM Bible is the definitive resource in JavaScript programming. I am never more than three feet from my copy.” — Steve Reich, CEO, PageCoders “This book is a must-have for any web developer or programmer.” — Thoma Lile, President, Kanis Technologies, Inc. “Outstanding book. I would recommend this book to anyone interested in learning to develop advanced Web sites. Mr. Goodman did an excellent job of organizing this book and writing it so that even a beginning programmer can understand it.” — Jason Hensley, Director of Internet Services, NetVoice, Inc. “Goodman is always great at delivering clear and concise technical books!” — Dwayne King, Chief Technology Officer, White Horse “JavaScript TM Bible is well worth the money spent!” — Yen C.Y. Leong, IT Director, Moo Mooltimedia, a member of SmartTransact Group “A must-have book for any internet developer.” — Uri Fremder, Senior Consultant, TopTier Software “I love this book! I use it all the time, and it always delivers. It’s the only JavaScript book I use!” — Jason Badger, Web Developer “Whether you are a professional or a beginner, this is a great book to get.” — Brant Mutch, Web Application Developer, Wells Fargo Card Services, Inc. “I never thought I’d ever teach programming before reading your book [JavaScript TM Bible]. It’s so simple to use — the Programming Fundamentals section brought it all back! Thank you for such a wonderful book, and for breaking through my programming block!” — Susan Sann Mahon, Certified Lotus Instructor, TechNet Training “I continue to get so much benefit from JavaScript TM Bible. What an amazing book! Danny Goodman is the greatest!” — Patrick Moss “Danny Goodman is very good at leading the reader into the subject. JavaScript TM Bible has everything we could possibly need.” — Philip Gurdon “An excellent book that builds solidly from whatever level the reader is at. A book that is both witty and educational.” — Dave Vane “I continue to use the book on a daily basis and would be lost without it.” — Mike Warner, Founder, Oak Place Productions “JavaScript TM Bible is by far the best JavaScript resource I’ve ever seen (and I’ve seen quite a few).” — Robert J. Mirro, Independent Consultant, RJM Consulting “First, I want to thank you for writing THE definitive book on JavaScript. I spent many hours in the computer aisles of bookstores, looking for a text to use for my class, and yours is hands-down the best I’ve seen. It’s now a required text for the course.” — Tom Travers, Instructor, University of New England JavaScriptBible 4th Edition Danny Goodman With a foreword by Brendan Eich, JavaScript’s creator Hungry Minds, Inc. New York, NY ✦ Cleveland, OH ✦ Indianapolis, IN JavaScript ™ Bible, 4th Edition Published by Hungry Minds, Inc. 909 Third Avenue New York, NY 10022 www.hungryminds.com Copyright © 2001 Danny Goodman. All rights reserved. No part of this book, including interior design, cover design, and icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise) without the prior written permission of the publisher. Library of Congress Control Number: 200101676 ISBN: 0-7645-3342-8 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 4B/SR/QT/QR/IN Distributed in the United States by Hungry Minds, Inc. Distributed by CDG Books Canada Inc. for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty. Ltd. for Australia and New Zealand; by TransQuest Publishers Pte Ltd. for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc. for Taiwan; by ICG Muse, Inc. for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria, and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R. Ltda. for Peru; by WS Computer Publishing Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for the Caribbean and West Indies; by Micronesia Media Distributor, Inc. for Micronesia; by Chips Computadoras S.A. de C.V. for Mexico; by Editorial Norma de Panama S.A. for Panama; by American Bookshops for Finland. For general information on Hungry Minds’ products and services please contact our Customer Care department within the U.S. at 800-762-2974, outside the U.S. at 317-572-3993 or fax 317-572-4002. For sales inquiries and reseller information, including discounts, premium and bulk quantity sales, and foreign-language translations, please contact our Customer Care department at 800-434-3422, fax 317-572-4002 or write to Hungry Minds, Inc., Attn: Customer Care Department, 10475 Crosspoint Boulevard, Indianapolis, IN 46256. For information on licensing foreign or domestic rights, please contact our Sub-Rights Customer Care department at 650-653-7098. For information on using Hungry Minds’ products and services in the classroom or for ordering examination copies, please contact our Educational Sales department at 800-434-2086 or fax 317-572-4005. For press review copies, author interviews, or other publicity information, please contact our Public Relations department at 650-653-7000 or fax 650-653-7500. For authorization to photocopy items for corporate, personal, or educational use, please contact Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, or fax 978-750-4470. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THERE ARE NO WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE ACCURACY AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES. Trademarks: JavaScript is a trademark or registered trademark of Sun Microsystems, Inc. All other trademarks are the property of their respective owners. Hungry Minds, Inc., is not associated with any product or vendor mentioned in this book. is a trademark of Hungry Minds, Inc. About the Author Danny Goodman is the author of numerous critically acclaimed and best-selling books, including The Complete HyperCard Handbook, Danny Goodman’s AppleScript Handbook, and Dynamic HTML: The Definitive Reference. He is a renowned authority and expert teacher of computer scripting languages and is widely known for his “JavaScript Apostle” articles at Netscape’s ViewSource online developer newsletter. His writing style and pedagogy continue to earn praise from readers and teachers around the world. To help keep his finger on the pulse of real-world programming challenges, Goodman frequently lends his touch as consulting programmer and designer to leading-edge World Wide Web and intranet sites from his home base in the San Francisco area. Credits Acquisitions Editor Debra Williams Cauley Project Editor Neil Romanosky Technical Editor David Wall Copy Editors Jerelind Charles Victoria Lee O’Malley Proof Editor Cordelia Heaney Project Coordinator Regina Snyder Graphics and Production Specialists Sean Decker LeAndra Johnson Stephanie Jumper Barry Offringa Kristin Pickett Jill Piscitelli Jeremey Unger Erin Zeltner Quality Control Technicians Laura Albert Valery Bourke Joel Draper Dwight Ramsey Permissions Editor Laura Moss Media Development Specialist Greg Stephens Media Development Coordinator Marisa Pearman Book Designer Kurt Krames Proofreading York Production Services Indexer Johnna VanHoose Dinse Cover Illustrator Kate Shaw Foreword A s JavaScript’s creator, I would like to say a few words about where JavaScript has been, where it is going, and how the book you’re holding will help you to make the most of the language. JavaScript was born out of a desire to let HTML authors write scripts directly in their doc- uments. This may seem obvious now, but in the spring of 1995 it was novel and more than a little at odds with both the conventional wisdom (that HTML should describe static doc- ument structure only) and the Next Big Thing (Java applets, which were hyped as the one true way to enliven and extend Web pages). Once I got past these contentions, JavaScript quickly shaped up along the following lines: ✦ “Java-lite” syntax. Although the “natural language” syntax of HyperTalk was fresh in my mind after a friend lent me The Complete HyperCard Handbook by some fellow named Goodman, the Next Big Thing weighed heavier, especially in light of another goal: script- ing Java applets. If the scripting language resembled Java, then those programmers who made the jump from JavaScript to Java would welcome similarities in syntax. But insist- ing on Java’s class and type declarations, or on a semicolon after each statement when a line ending would do, were out of the question — scripting for most people is about writ- ing short snippets of code, quickly and without fuss. ✦ Events for HTML elements. Buttons should have onClick event handlers. Documents load and unload from windows, so windows should have onLoad and onUnload han- dlers. Users and scripts submit forms: thus the onSubmit handler. Although not initially as flexible as HyperCard’s messages (whose handlers inspired the onEvent naming con- vention), JavaScript events let HTML authors take control of user interaction from remote servers and respond quickly to user gestures and browser actions. With the adoption of the W3C DOM Level 2 event handling recommendations, JavaScript in mod- ern browsers has fully flexible control over events. ✦ Objects without classes. The Self programming language proved the notion of proto- type-based inheritance. For JavaScript, I wanted a single prototype per object (for sim- plicity and efficiency), based by default on the function called using the new operator (for consonance with Java). To avoid distinguishing constructors from methods from functions, all functions receive the object naming them as the property that was called, in the this parameter. Although prototypes didn’t appear until Navigator 3, they were prefigured in Version 2 by quoted text being treated as an object (the String object pro- totype, to which users could attach methods). ✦ Generated HTML. Embedding JavaScript in HTML gave rise to a thought: Let the script speak HTML, as if the emitted text and markup were loaded in place of the script itself. The possibilities went beyond automating current or last-modified dates, to com- puting whole trees of tables where all the repeated structure was rolled up in a scripted loop, while the varying contents to be tabulated came in minimal fashion from JavaScript objects forming a catalog or mini-database. At first, I thought JavaScript would most often find use in validating input to HTML forms. But before long, I was surprised to see how many Web designers devised com- pelling applications by way of script-generated HTML and JavaScript objects. It became clear from user demonstration and feedback that Web designers sought to build signifi- cant applications quickly and effectively with just a few images, HTML, and JavaScript. Eventually they demanded that the browser support what is now known as “Dynamic HTML” (one fun link: http://www.javascript-games.org/). As legions of Web authors embraced the authoring power of JavaScript, they, in turn, demonstrated the crucial advantages of a scripting environment over old-school applica- tion development. Not only were the HTML and JavaScript languages comparatively easy to use, but development did not require the programming expertise needed to light all pixels and handle all events as in a big, traditional application. The primacy of JavaScript on the Web today vindicates our early belief in the value of a scripting language for HTML authors. By keeping the “pixel-lighting” bar low, HTML with images has made Web designers out of millions of people. By keeping the “event-handling” bar low, JavaScript has helped many thousands of those designers become programmers. Perhaps the ultimate example of web development’s convergence with application devel- opment is the Mozilla browser, wherein all of the user-interface and even some custom widgets and modular components are implemented entirely using JavaScript, Cascading Style Sheets (CSS), custom XML-based markup languages, and images. JavaScript is also a general language, useful apart from HTML and XML. It has been embedded in servers, authoring tools, browser plug-ins, and other kinds of browsers (for such things as 3D graphical worlds). Its international standard, ECMA-262 ( ISO 16262), has advanced to a Third Edition. But compared to languages such as Perl and even Java, it is still relatively young. Work toward a Fourth Edition of the language, sup- porting optional types, classes, and versioning facilities, progresses within the ECMA technical committee (see the “JS2” proposal to the ECMA technical committee docu- mented at http://www.mozilla.org/js/language/js20/). It is clear to me that JavaScript would not have survived without a creative, loyal, and patient community of developers; I owe them each a huge debt of thanks. Those develop- ers who took up the beta releases of Navigator 2, and disseminated vital workarounds and feature requests by e-mail and net-news, are the language’s godparents. Developer sup- port and feedback continue to make JavaScript the eclectic, rambunctious success it is. The book in your hands compiles thousands of those “developer miles” with the insight of an expert guide and teacher. Danny didn’t know at the time how much inspiration I found in his HyperCard book, but it was on my desk throughout the development of JavaScript in 1995. His energy, compassion, and clear prose helped me keep the goal of “a language for all” in mind. It is enormously gratifying to write the foreword to the fourth edition of this book, which has earned so many “satisfied reader miles.” I highly recommend Danny Goodman’s JavaScript Bible to anyone who wants to learn JavaScript, and especially to those HTML authors who’ve so far written only a few scripts or programs — you’re in for a lifetime of fun on the “scripting road” with a trusty guide at your side. Brendan Eich The Mozilla Organization (http://www.mozilla.org) viii JavaScript Bible, 4th Edition Preface F or nearly 20 years, I have written the books I wished had already been written to help me learn or use a new technology. Whenever possible, I like to get in at the very beginning of a new authoring or programming environment, feel the grow- ing pains, and share with readers the solutions to my struggles. This fourth edition of the JavaScript(tm) Bible represents knowledge and experience accumulated over five years of daily work in JavaScript and a constant monitoring of newsgroups for questions, problems, and challenges facing scripters at all levels. My goal is to help you avoid the same frustration and head scratching I and others have experienced through multiple generations of scriptable browsers. While previous editions of this book focused on the then predominant Netscape Navigator browser, the swing of the browser market share pendulum currently favors Microsoft Internet Explorer. At the same time, Netscape has accomplished the admirable task of reinventing its own browser in light of rapidly advancing industry standards. As a result of both of these trends, this massively revised and expanded fourth edition treats both brands of browsers as equals as far as scripters are con- cerned. You hear my praise and dismay at various scripting features of both browser families. But empowering you to design and write good scripts is my passion, regard- less of browser. Therefore, the book contains details about proprietary and standard implementations to equip you to choose the development path that best fits your content’s audience. If you detect any bias of mine throughout this book, it is a desire, where possible, to write scripts that work on as many browsers as possible. Organization and Features of This Edition Because of the greatly expanded range of vocabularies that scripts may use in the latest browser versions, the biggest change to the structure of the book is in the ref- erence portion. In this edition, you find a greater distinction between the document object model and core JavaScript language reference sections. This new division should help those readers who are primarily interested in only the JavaScript lan- guage (for use in other applications) find what they need more quickly. Here are some details about the book’s structure. Part I Part I of the book begins with a chapter that shows how JavaScript compares with Java and discusses its role within the rest of the World Wide Web. The Web browser and scripting world have undergone significant changes since JavaScript first arrived on the scene. That’s why Chapter 2 is devoted to addressing challenges facing x Preface scripters who must develop applications for both single- and cross-platform browser audiences amid rapidly changing standards efforts. Chapter 3 provides the first foray into JavaScript, where you get to write your first practical script. Part II All of Part II is handed over to a tutorial for newcomers to JavaScript. Nine lessons provide you with a gradual path through browser internals, basic programming skills, and genuine JavaScript scripting. With only a couple of clearly labeled items, the lessons cover scripting topics that apply to all scriptable browsers. Exercises fol- low at the end of each lesson to help reinforce what you just learned and challenge you to use your new knowledge ( you’ll find answers to the exercises in Appendix C). The goal of the tutorial is to equip you with sufficient experience to start scripting simple pages right away while making it easier for you to understand the in-depth discussions and examples in the rest of the book. By the end of the final lesson, you’ll know how to script multiple frame environments and even create the mouse- rollover image swapping effect that is popular in a lot of Web pages these days. Part III Part III, the largest section of the book, provides in-depth coverage of the document object models as implemented in browsers from the earliest days to today. In all ref- erence chapters, a compatibility chart indicates the browser version that supports each object and object feature. One chapter in particular, Chapter 15, contains ref- erence material that is shared by most of the remaining chapters of Part III. To help you refer back to Chapter 15 from other chapters, a dark tab along the outside edge of the page shows you at a glance where the chapter is located. Additional naviga- tion aids include guide words at the bottoms of most pages to indicate which object and object feature is covered on the page. Part IV Reference information for the core JavaScript language fills Part IV. As with refer- ence chapters of Part III, the JavaScript chapters display browser compatibility charts for every JavaScript language term. Guide words at the bottoms of pages help you find a particular term quickly. Part V In Part V, I get down to the business of deploying JavaScript. Here are the practical aspects of JavaScript, such as Chapter 43’s coverage of client-side form data valida- tion and Chapter 44’s coverage of blending Java applets and plug-ins into pages. Debugging scripts is the focus of Chapter 45, with tips on understanding error mes- sages, building your own debugging tools, and using Netscape’s debugger. Chapter 46 goes into great detail about security issues for JavaScript-enabled applications. [...]... declarations, however, are quite different, because JavaScript is a loosely typed language A variable can contain an integer value in one statement and a string in the next (though I’m not saying that this is good style) What Java refers to as methods, JavaScript calls methods (when associated with a predefined object) or functions (for scripter-defined actions) JavaScript methods and functions may return... JavaScript Handbook and JavaScript Bible) for investing in this ongoing effort I wish I had the space here to acknowledge by name so many who have sent e-mail notes and suggestions: Your input has been most welcome and greatly appreciated Now it’s time to get down to the fun of learning JavaScript Enjoy! A Word from the Publisher The expanded content of this edition far exceeds the number of pages... Windows The remaining nine chapters consist of full-fledged applications of JavaScript These applications are designed not necessarily as plug-and-play modules you can put into your pages right away Instead, their goal is to demonstrate many of the concepts described earlier in the book by way of real-world examples New for this edition are some examples based on XML data islands in Internet Explorer for... O’Malley ( Hungry Minds, Inc.); technical reviewer David Wall; “cookie man” Bill Dortch ( hIdaho Design); Red and his friends ( Mars, Incorporated); and fellow scripters and newsgroup kibitzers, who unwittingly advised me as to where scripters were having trouble with the language Above all, I want to thank the many readers of the first three editions of this book (with both titles, Danny Goodman’s JavaScript. .. transition from procedural to object-oriented programming may be the most difficult challenge for you When I was first introduced to object-oriented programming a number of years ago, I didn’t get it at first But when the concept clicked — a long, pensive walk helped — so many light bulbs went on inside my head that I thought I might glow in the dark From then on, object orientation seemed to be the only... these physical limits, we have moved selected chapters of more advanced subjects to the CD-ROM in searchable Acrobat format We trust that the added value of these unabridged electronic chapters outweighs the associated inconvenience Contents at a Glance Foreword vii Preface ix Acknowledgments ... Chapter 31: Positioned Objects—Summary 885 Chapter 31: Positioned Objects CD-205 Chapter 32: Embedded Objects—Summary 887 Chapter 32: Embedded Objects CD-255 Chapter 33: XML Objects—Summary 889 Chapter 33: XML Objects CD-275 Part IV: JavaScript Core Language... Positioned Objects—Summary 885 What Is a Layer? 886 Chapter 31: Positioned Objects CD-205 What Is a Layer? CD-206 NN4 Layer Object CD-207 Positioned Elements in the Modern DOM CD-227 Chapter 32: Embedded Objects—Summary 887 Chapter 32: Embedded... JavaScript are the object-oriented notions of classes, inheritance, instantiation, and message passing These aspects are simply non-issues when scripting At the same time, however, JavaScript s designers knew that you’d have some hard-to-break habits For example, although JavaScript does not require a semicolon at the end of each statement line, if you type one in your JavaScript source code, the JavaScript. .. Chapter 40: JavaScript Operators 1025 Chapter 41: Functions and Custom Objects 1053 Chapter 42: Global Functions and Statements 1091 Part V: JavaScriptTM Bible, Gold Edition Preview 1115 Part VI: Appendixes 1125 Appendix A: JavaScript and Browser Object Quick Reference 1127 Appendix B: JavaScript . England JavaScript ™ Bible 4th Edition Danny Goodman With a foreword by Brendan Eich, JavaScript s creator Hungry Minds, Inc. New York, NY ✦ Cleveland, OH ✦ Indianapolis, IN JavaScript ™ Bible, 4th Edition Published. 200101676 ISBN: 0-7645-3342-8 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 4B/SR/QT/QR/IN Distributed in the United States by Hungry Minds, Inc. Distributed by CDG Books Canada Inc IN JavaScript ™ Bible, 4th Edition Published by Hungry Minds, Inc. 909 Third Avenue New York, NY 10022 www.hungryminds.com Copyright © 2001 Danny Goodman. All rights reserved. No part of this book, including

Ngày đăng: 28/04/2014, 16:50

TỪ KHÓA LIÊN QUAN