![[Book Cover]](../covergif/0138419418.jpg)
|
Jumping JavaScript, 1/e
Janice Winsor, Half Moon Bay, California
Brian Freeman, Mountain View, California
Sun Microsystems Press, Palo Alto, CA
Published July, 1997 by Prentice Hall PTR (ECS Professional)
Copyright 1998, 1216 pp.
Paper Bound w/CD-ROM
ISBN 0-13-841941-8
$49.95
|
Sign up for future mailings on this subject.
See other books about:
JAVA
![[Preface]](../images/cat_preface.gif)
|
The JavaScript guide that delivers!
JavaScript is the quickest, easiest way to build interactive Web pages. It's a tool useful to every Internet and intranet developer.
Jumping JavaScript delivers everything you need to get results immediatelyincluding hundreds of script examples on CD-ROM, all designed for Windows 95, Macintosh, and UNIX. Even better, it is a comprehensive, well-indexed bookcovering all the advanced techniques you need to become a world-class JavaScript developer.
Get started with the basics of the JavaScript language and scripting environment, including data types, variables, functions, operators, expressions and statements, debugging tips, and programming style. Next, discover JavaScript's powerful objects; learn how to create windows and documents, control and use history properties, embed images and Java code.
Jumping JavaScript contains detailed coverage of:
- Understanding script writing basics, the Navigator object hierarchy and their event handlers.
- Developing forms with user interface elements to capture user input.
- Controlling scripts: JavaScript operators, testing for conditions, and creating loops.
- Creating links and active image areas.
- Working with system objects, including the String, Array, Date, and Math objects.
- Working with the Navigator, MimeType, and Plugin objects.
- Creating your own JavaScript objects and working with cookies.
Whether you're responsible for a Web site or corporate intranet, Jumping JavaScript is the one book you need to leverage all the power of JavaScript.
JANICE WINSOR is the award-winning author of the best selling Solaris System Administrator's Guide and Solaris Advanced System Administrator's Guide and the author of the recently published UNIX Book of Games (all Sun Microsystems Press). She is experienced at explaining complicated technology to the average user in plain, easy-to-understand English. Janice is currently a manager at The Filoli Information Systems and lives in Half Moon Bay, California, with her three cats.
BRIAN FREEMAN is a software engineer experienced with desktop, multimedia, and internet technologies. He has worked in the computer industry for more than nine years, the last six for Sun Microsystems, Inc. in JavaSoft's Software Products and SunSoft's Desktop Technologies organizations. He recently moved to Silicon Graphics, Inc. and joined the Silicon Surf team as the technical lead for their Web site.
Preface.
Acknowledgments.
I. GETTING STARTED.
1. Introducing the JavaScript Language.
The JavaScript Language. JavaScript-Enabled Browsers. Client-Side
JavaScript. Server-Side JavaScript. The Internet. Network Protocols.
IP Addresses. Domains. The World Wide Web. How the World Wide Web
Works. Helper Applications. Plug-ins. Java Applets. Summary of New
Terms and Concepts.
2. Introducing the Scripting Environment.
Hello World Tradition. Scripting Terminology. Understanding
the Elements of the Hello World Script. JavaScript and HTML. Embedding
a Script. Adding Text for Non-JavaScript Browsers. Loading a Script
File. Adding JavaScript Comments. Adding HTML Comments. Displaying
Text. Using the Basic Template. Immediate Activation Template. Deferred
Activation. Recommended Programming Style Guide. General Comments
and Rules. Comments. Code Indentation. White Space. Statements. Comparisons.
Identifier Style (Variable, function, and object name choices). Variables.
Functions. Objects. Source Files (.js Files to be Included in a Script).
Looking at the Script-Writing Process. Creating the Hello World Script.
Running the Hello World Script. Summary of New Terms and Concepts.
3. Introducing General Scripting Concepts.
Data Types. Variables. Identifiers. White Space. Literal
Values. Declaring a Variable. Assigning a Value to a Variable. Initializing
a Variable. Functions. Operators. Precedence. Mathematical Operators.
Expressions. Statements. Summary of New Terms and Concepts.
4. Debugging Scripts.
Syntax Errors. Design or Logic Errors. HTML Layout and Script
Parsing Order. Operator Precedence. JavaScript Error Messages. Function
does not always return a value. identifier is a reserved word. missing
) after argument list. missing } after function body. missing ; after
for-loop condition. missing ; after for-loop initializer. nested comment.
out of memory. something cannot be indexed as an array. something
has no properties. something is not defined. something is not a function.
something is not a numeric literal. syntax error. unterminated string
literal. Some Debugging Tips and Tricks. Using Netscape JavaScript
Protocol to Debug Statements. Using Alerts to Set Breakpoints. String
Formatting Tip. Looking at Object Properties. Debugging Checklist.
Summary of New Terms and Concepts.
II. CREATING HTML PAGES.
5. Introducing Objects.
Object Properties. Object Methods. Referencing Object Properties
and Methods. Events. Object-Manipulation Statements. The this Keyword.
The for...in Statement. The with Statement. The new Statement. Built-in
Objects. Summary of New Terms and Concepts.
6. Creating Windows.
Displaying a Status Message. Example of status and defaultStatus
Properties. Explanation of Example Script. Example of status and defaultStatus
Properties with a Timeout. Controlling the Structure of a Window.
The frames Property. The length Property. Referring to a Window. Examples
of frame and Window Naming Properties. Explanation of Example Scripts.
A Three-Frame Window Example. Referencing document, history, and location
Objects in a Window. Example of Referencing document, history, and
location Objects. Opening a New Window. Examples of open() Method.
Finding Which Window Is the Opener. Example of window.opener Property.
Using the unescape() Function to Reformat Location Values. Determining
the State of a Newly Opened Window. Example of Using the closed Property.
Displaying Informational Messages in an Alert Window. Example of the
alert( ) Method. Explanation of the windowAlert.html Script. Closing
a Window. Example of the close() Method. Displaying a Confirmation
Message. Example of confirm() Method. Prompting Users for Input. Example
of prompt() Method. Controlling the Input Focus in Windows. Example
of blur() and focus() Methods. Using Event Handlers to Control Window
Focus. Example of onBlur and onFocus Event Handlers. Moving Around
within a Window. Example of scroll() Method. Using Timeouts. Example
of Timeouts in a Script. Using Event Handlers on Load and Unload.
Example of onLoad and onUnload Event Handlers. Using an Event Handler
to Capture Interpreter Error Messages. Example of Capturing and Displaying
Error Messages. Explanation of windowOnerrorHandler.html Script. Example
of Hiding Error Messages. Summary of New Terms and Concepts.
7. Creating Documents.
Controlling Document Colors. Example of Setting Document
Colors. Extracting Title, Location, Modification, and Document Referrer
Information for a Document. Example of Displaying All of the Properties
of a Document. Example of Comparison of location and URL Document
Properties. Example of Finding Where a Document Came From. Working
with the anchors Property. Example of Using a Named Anchor. Example
of an Anchor That Is Also a Link. Example of a Link to Another Window.
Example of Using Anchors to Move Around in a Document. Example of
Using the Anchors Array. Working with the links Property. Example
of Using the links Property. Referencing Forms in a Document. Example
of Referencing Forms in a Document. Referencing Images in a Document.
Example of Using the Images Array. Referencing Java Applets in a Document.
Example of Including a Java Applet. Finding Plug-ins Embedded in a
Document. Example of Counting Plug-Ins. Finding the Document Domain.
Example of Finding the Document Domain. Storing User-Generated Information:
the cookie Property. Limitations of the cookie Property. Example of
Creating a cookie Property. Writing into a Document. Opening, Closing,
and Clearing a Document. Example of Document Methods. Summary of New
Terms and Concepts.
8. Controlling History.
Displaying history Properties. Determining the Number of
URL Links. Example of the history.length Property. Navigating the
History List. Example of history.forward() and history.back() Methods.
Example of Using Images with forward and back Methods. Example of
history.go() Method. Data Tainting and History Properties. Example
of current, previous, and next Properties. Extracting Information
from the History List. Example of toString() Method. Summary of New
Terms and Concepts.
9. Working with Images.
Using the src Property. Example of Using image.src to Substitute
Images. Prestaging Images with the lowsrc Property. Example of Prestaging
Big Images with Low-Resolution Files. Checking If an Image Has Completed
Loading. Example of Checking If an Image Has Completed Loading. Using
Read-Only Image Properties. Example of Displaying Image Properties.
Using the Image Constructor. Example of Using the Image Constructor.
Example of Animation Script. Using the onLoad Event Handler. Using
the onLoad Event Handler to Display an Alert. Using the onLoad Event
Handler to Create a Slide Show. Using the onLoad Event Handler to
Change the Image Source. Getting into Trouble with the onLoad Event
Handler. Planning for Error Handling. Using the onError Event Handler
to Catch Errors. Planning for the Stopping of Image Loading. Using
the onAbort Event Handler When Users Click on the Stop Button.
10. Embedding Java Applets in Your Web Page.
Applet Files. Downloading the JDK. Running the Java Compiler.
Running the Applet Viewer. Applet HTML Review. Applet HTML Attributes.
Applet Parameters. Using the Java Console. Adding an Applet to a Script
by Using a Class File. Example of Adding an Applet by Using a Class
File. Adding an Applet to a Script by Using an Archive File. Example
of Adding an Applet by Using an Archive File. Controlling Applet Parameters
from a Script. Example of Controlling Applet Parameters from a Script.
Referencing an Applet by Using the document.applet Property. Example
of Referencing an Applet by Using Document Properties. Applets and
LiveConnect. Summary of New Terms and Concepts.
11. Using the plugin Object.
Embedding a Plug-in in a Document. Accessing the plugin/embeds
Array. Using the plugin Object Properties. Example of Using the plugin
Object Properties. Example of Displaying Plug-in File Names. Example
of Displaying Plug-in Names. Updating the List of Plug-ins Available
to the Browser. Example of Updating the List of Plug-ins Available
to the Browser. Checking to Determine if a Plug-in Is Available. Example
of Checking to Determine if a Plug-in Is Available. Controlling a
Plug-in. Example of Controlling a Plug-in from a Script. Plug-ins
and LiveConnect. Summary of New Terms and Concepts.
III. NAVIGATING ON THE WEB.
12. Controlling Location.
Using the location Object Without Any Properties. Properties
of the location Object. Referencing the Complete URL. Referencing
the Protocol. Example of Referencing Different Protocols. Referencing
the Host, Host Name, and Port. Data Tainting. Example of Using the
host, host name, and port Properties. Referencing the Path Name. Referencing
the Hash. Example of Using the hash Property. Referencing Search Queries.
Example of Using location Object Properties. Reloading a Document
from a Script. Example of Reloading a Document from a Script. Replacing
a URL in the History List. Example of Replacing a URL in the History
List. Summary of New Terms and Concepts.
13. Creating Active Image Areas.
Emulating an onClick Event Handler for the area Object.
Example of Using the javascript: Protocol to Emulate an OnClick Event
Handler. Displaying a Status Message with an onMouseOver Event Handler.
Example of Displaying a Status Message with an onMouseOver Event Handler.
Clearing a Status Message with an onMouseOut Event Handler. Example
of Clearing a Message from the Status Bar. Creating an Image Map.
Example of Creating an Image Map.
14. Working with Links.
Determining the Number of Links in a Document. Example of
Determining the Number of Links in a Document. Specifying the Link
Target Location. Using an onClick Event Handler Before a Link Is Navigated.
Displaying a Status Message with onMouseOver. Example of Displaying
a Status Message with onMouseOver. Clearing a Status Message with
onMouseOut. Example of Clearing a Status Message with onMouseOut.
Using Other Protocols with a Link. Example of Linking to the javascript
Protocol.
IV. GETTING USER INPUT.
15. Introducing form Objects.
Retrieving the Form That Contains the Object. Determining
the Type of a form Object. Example of Determining the Type of a Form.
Evaluating Expressions. Converting an Object to a String. Determining
the Value of an Object.
16. Adding Text Fields to a Document.
Defining Text Fields. Example of Creating a Text Field.
text Object Terminology. Text Field Locations. The text Object. Naming
text Objects. Getting and Setting text Object Values. Example of Using
the text.value Property. Analysis of the textValue.html Script. Getting
a Default Value for a text Object. Example of Using the defaultValue
Property. Analysis of textDefaultValue.html Script. Setting the Input
Focus. Removing Input Focus. Example of focus( ) and blur( ) Methods.
Automatically Selecting Text. Using the onChange Event Handler to
Validate Data. Example of Validating Text by Using the onChange Event
Handler. Catching an Event when the Text Field Has the Focus. Catching
an Event when Text Is Selected. Catching an Event when a Text Field
Loses the Focus. Catching an Event when the User Changes to Another
Text Field. Example Using text Object Event Handlers. Summary of New
Terms and Concepts.
17. Defining a Password Field.
Example of Creating a Password Field. Password Field Locations.
The password Object.
18. Adding Text Areas to a Document.
Defining Text Areas. Example of Creating a Text Field. Text
Area Locations. The textarea Object.
19. Activating Buttons in a Document.
Defining the Button Action. Referencing Button Names and
Values. The click Method. Example of onClick Event Handler. Example
of Using the click() Method. Security Loophole with click() Method.
submit and reset Objects. Example of the reset Object. Summary of
New Terms and Concepts.
20. Using Check Boxes.
Defining Check Boxes. Example of Creating a Check Box. Check
Box Locations. The checkbox Object. Getting checkbox Object Names.
Getting checkbox Object Values. Example of Using Check Box Values.
Getting and Setting Check Marks. Example of Using the checked Property.
Getting a Default Value for a checkbox Object. Determining the Type
of a Form Object. Example of checkbox.type. Clicking on a Check Box.
Example of Using the click() Method. Performing Script Actions onClick.
Example of onClick Event Handler for the checkbox Object. Example
of a Restaurant Review Form.
21. Using Radio Buttons and Hidden Objects.
Defining Radio Buttons. Example of Creating Radio Buttons.
Radio Button Locations. Using the hidden Object to Store Radio Button
Values. Example of Using the hidden Object with Radio Buttons. The
radio Object. Getting radio Object Names. Getting radio Object Values.
Counting the Number of Radio Buttons in a Set. Example of Using the
radio.length Property. Determining Which Radio Button Is Checked.
Getting a Default Value for a radio Object. Clicking on a Radio Button.
Example of a Script Clicking on a Radio Button. Performing Script
Actions on Click.
22. Using Selection Lists.
Defining Selection Lists. Creating a Default Selection List.
Showing All of the Options in a Selection List. Creating a Multiple-Selection
List. Selection List Locations. The select Object. Getting select
Object Names. Counting the Number of Options in a Selection List.
Determining Which Options Are Selected. Initiating an Action when
an Option Is Changed. Example of the onChange Event Handle. Changing
the Blur and Focus of a Selection List. Referencing Individual Options.
Getting a Default Value for an Option. Example of Using a Loop to
Evaluate Values and Reset Defaults. Analysis of selectLength.html
Script. Getting and Setting the Selected Value for an Option. Example
of Evaluating Selections. Getting and Setting the Text String for
an Option. Example of Setting and Extracting Text Strings for an Option.
Getting and Setting the Value for an Option. Example of Getting and
Setting the Value for an Option. Getting the Index Value for an Option.
Dynamically Adding Options to a Selection List. Example of Using the
Option() Constructor.
23. Including Files in an Upload.
Creating a fileUpload Object. Example of Creating a fileUpload
Object. Displaying Properties of the fileUpload Object. Example of
Displaying Properties of the fileUpload Object. Determining the Name
of the fileUpload Object. Example of Determining the Name of the fileUpload
Object. Determining the Value of the fileUpload Object. Example of
Determining the Value of the fileUpload Object. Displaying the Type
of a Form. Example of Displaying the Type of a fileUpload. Controlling
Keyboard Focus. Example of Controlling Keyboard Focus. Handling Events
when the Keyboard Focus Changes.
24. Using Forms to Send Data to a Server.
Overview of How a Form Is Submitted. Example of Displaying
Form Properties in a Window. Determining the Number of Input Elements
in a Form. Example of Determining the Number of Input Elements in
a Form. Specifying Where to Send Your Forms Data. Example of Specifying
Where to Send Your Forms Data. Specifying How Data Is Transmitted.
Example of a Form That Uses GET. Example of a Form That Uses POST.
Specifying the Window or Frame That Receives Server Output. Example
of Specifying a Window or Frame to Receive Server Output. Encoding
Form Data with a MIME Type. Submitting a Form. Resetting a Form to
Its Default Values. Example of Resetting a Form to Its Default Values.
Controlling Actions when Users Submit a Form. Controlling Events When
Users Reset a Form. Example of Controlling Events When Users Reset
a Form. Summary of New Terms and Concepts.
V. CONTROLLING YOUR SCRIPTS.
25. Understanding Operators.
Mathematical Operators. Assignment Operators. Comparison
Operators. Unary Operators. Binary (or Bitwise) Operators. Operator
Precedence. Summary of New Terms and Concepts.
26. Testing for Conditions.
Boolean Operators. Testing for a Single Condition. Testing
for Multiple Conditions. Nesting if ... else Statements. Conditional
Operator. Summary of New Terms and Concepts.
27. Creating Loops. Repeat Loops (for, for ... in).
Repeatedly Executing a Group of Commands (while). Looping
Through Properties (for var in object). Referencing a Specific Object
in a Loop (with). Controlling Loop Execution (continue). Breaking
Out of a Loop (break). Summary of New Terms and Concepts.
VI. USING SYSTEM OBJECTS.
28. Working with Strings and String Objects.
Defining a String. Creating a String Data Type. Creating
a String Object. Example of the Difference Between a String Data Type
and a String Object. Combining String Literals and Variables. String
Formatting Escape Characters. Converting Numbers to Strings. Converting
Strings to Numbers. Evaluating Text Expressions. Escaping and Unescaping
ASCII Characters. Introducing the String Object. Finding the Number
of Characters in a String. Example of Finding the Number of Characters
in a String. Creating Custom String Functions. Example of Creating
a Custom String Function. Converting a String into an Anchor or a
Link. Example of Converting a String into an Anchor and a Link. Using
String Object Methods to Format Text. Example Using String Object
Methods to Format Text. Example of Changing Font Size and Color. Converting
Case. Searching for Part of a String. Example of Searching for Part
of a String with the indexOf() Method. Example of Searching for Part
of a String with the lastIndexOf() Method. Getting a Substring. Getting
the nth Character in a String. Example of Getting the nth Character
in a String. Splitting a String into an Array. Summary of New Terms
and Concepts.
29. Working with Arrays.
Constructing an Array. Example of Creating New Array Objects.
Determining the Length of an Array. Extracting String Data from an
Array. Reversing the Order of Data in an Array. Example of Reversing
the Order of Data in an Array. Sorting Items in an Array. Example
of Sorting an Array. Creating Your Own Properties for an Array Object.
Summary of New Terms and Concepts.
30. Using the Date Object.
Creating a Date Object. Example of Creating a Date Object.
Parsing Date Strings. Example of Parsing a Date. Getting and Setting
Date and Time Elements. Getting and Setting the Date of the Month.
Getting and Setting the Month. Getting the Day of the Week. Getting
and Setting the Year. Getting and Setting the Time. Getting and Setting
the Hour. Getting and Setting the Minute. Getting and Setting the
Second. Example of Getting and Setting Date and Time Elements. Getting
the Time Zone Offset. Obtaining a Date String in GMT Format. Obtaining
a Date String in the Current Locale. Universal Coordinated Time. Example
of Using the Date.UTC() Method. Creating Your Own Properties for a
Date Object. Summary of New Terms and Concepts.
31. Doing Math.
Using Constants. Example of Using Constants. Comparing Values.
Example of Finding the Largest Value. Example of Finding the Smallest
Value. Rounding Numbers. Returning an Absolute Value. Rounding a Number
Up. Rounding a Number Down. Rounding Numbers. Generating Random Numbers.
Example of Generating Random Numbers. Calculating Square Roots. Example
of Calculating Square Roots. Using Trigonometric Methods. Finding
the Arc Cosine. Calculating the Arc Sine. Calculating the Arc Tangent.
Calculating the Angle of Polar Coordinates. Calculating the Cosine.
Calculating the Sine. Calculating the Tangent. Changing the Power
of a Number. Example of Changing the Power of a Number. Calculating
Natural Logarithms. Example of Calculating Natural Logarithms. Computing
Ex. Example of Computing Ex. Summary of New Terms and Concepts.
32. Using the navigator Object.
Displaying navigator Properties. Identifying the Browser
Software. Example of Identifying the Browser Software by Name. Example
of Identifying the Browser Software by Code Name. Identifying the
Platform and Version of the Browser. Example of Identifying the Platform
and Version of the Browser. Example of Identifying the HTTP User Agent
Value. Testing Whether Java Is Enabled. Example of Testing Whether
Java Is Enabled. Testing Whether Data Tainting Is Enabled. Example
of Testing Whether Data Tainting Is Enabled. The plugin and mimeType
Properties.
33. Specifying MIME Types.
The mimeType Object. Accessing a Description of a MIME Type.
Determining the Plug-in That Handles the MIME Type. Example of Determining
the Plug-in That Handles the MIME Type. Determining the Type of a
MIME Type. Example of Determining the Type of a MIME Type. Determining
MIME Type Suffixes. Example of Determining MIME Type Suffixes. Summary
of New Terms and Concepts.
VII. ADVANCED JAVASCRIPT.
34. Creating Your Own JavaScript Objects.
Using the function Object. Determining Who Called a Function.
Determining the Arguments Passed to a Function. Creating Prototype
Methods for a Function. Creating Custom Object Functions. Creating
an Instance of a Custom Object. Accessing Custom Object Properties
and Methods. Creating a Custom Name Object. Displaying Property Values
for a Custom Object. Creating a Prototype Method for a Custom Object.
Combining Custom Objects.
35. Controlling Script Input and Output with the cookie
Property.
Location of the Cookie File. Limitations of the cookie Property.
Security Issues and Cookies. Accessing Cookies from JavaScript. Accessing
Public-Domain Cookie Functions. Creating a Basic Cookie Name. Creating
a Cookie with a Path Name. Setting an Expiration Date for a Cookie.
Deleting a Cookie. Setting a Cookie Domain. Creating a Secure Cookie.
A Complex Cookie Example. Summary of New Terms and Concepts.
36. Controlling Data Tainting.
Enabling Data Tainting on Your Platform. When You Should
Enable Data Tainting. UNIX Systems. Windows Systems. Macintosh Systems.
Accessing Windows with Tainted Data. Tainting Data. Example of Tainting
Data. Untainting Data. Example of Untainting a Property. Example of
Trying to Untaint the Property from Another Script. Summary of New
Terms and Concepts.
VII. APPENDIXES.
Appendix A HTML Frames. What Are Frames? Frame Components.
Creating Frames. Changing Frame Column Sizes. Creating Vertical Frames.
Creating a Compound Frame. Creating the Nested Frame. Creating a Named
Frame. Special Frames. Making a New Browser Window. For No-Frame Clients.
Scrolling. Establishing Margins. Design Concerns. Appendix B. JavaScript
Predefined Colors Appendix C. JavaScript Quick Reference. JavaScript
Objects. Anchor Object. applet Object. Area Object. Array Object.
button Object. Event Handlers. checkbox Object. Date Object. document
Object. fileUpload Object. form Object. function Object. hidden Object.
history Object. image Object. link Object. location Object. Math Object.
mimeType Object. navigator Object. password Object. plugin Object.
radio Object. reset Object. select Object. String Object. submit Object.
text Object. textarea Object. window Object. Control Structures. Operators.
JavaScript Functions and Methods. Reserved JavaScript Keywords. Escape
Characters for String Formatting. HTTP MIME Types. Glossary. Index.
|