Second Edition
201 West 103rd Street, Indianapolis, Indiana 46290
Pure JavaScript, Second Edition
Copyright © 2002 by Sams Publishing
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.
International Standard Book Number: 0-672-32141-6
Library of Congress Catalog Card Number: 00-111512
Printed in the United States of America
First Printing: August 2001
04 03 02 01 4 3 2 1
Trademarks
All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The author(s) and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book or from the use of the CD or programs accompanying it.
ACQUISITIONS EDITOR
Shelley Johnston
Markanday
DEVELOPMENT EDITOR
Jonathan Steever
MANAGING EDITOR
Charlotte Clapp
PROJECT EDITOR
Elizabeth Finney
COPY EDITOR
Rhonda Tinch-Mize
INDEXER
Sandra Henselmeier
PROOFREADERS
Antonio Reitz
Rebecca Martin
Debra Sexton
TECHNICAL EDITOR
Andrew Watt
TEAM COORDINATOR
Amy Patton
MEDIA DEVELOPER
Dan Scherf
INTERIOR DESIGNER
Karen Ruggles
COVER DESIGNER
Aren Howell
PAGE LAYOUT
Ayanna Lacey
|
| |
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
|
| |
|
| |
| ||
| ||
| ||
| ||
| ||
|
R. Allen Wyke, of Durham, North Carolina is vice president of Research and Development at the eMarketing solutions company Engage, where he works with product managers, product marketing, and engineering to help ensure that their products have the proper vision and direction in both online and offline worlds. He has also developed intranet Web pages for a leading telecommunications and networking company, as well as worked on several Internet sites.
Wyke is the author of seven books on various Internet technologies including Perl, JavaScript, and PHP. In the past, he has also written the monthly Webmaster column for SunWorld, and a weekly article, “Integrating Windows and Unix,” for ITworld.com.
Jason D. Gilliam is a software developer at ichat, Inc. At ichat, he develops Web-based chat and discussion group software using C++, JavaScript, HTML, and various other Internet technologies. In addition to his work at ichat, he has developed intranet Web pages and numerous C++ applications for a leading telecommunications company and has worked on several Internet sites for other organizations. Gilliam is also a contributing author to JavaScript Unleashed, Third Edition. He holds a bachelor’s degree in Computer Engineering from North Carolina State University. Jason and his wife live in Cary, North Carolina.
Charlton Ting, of Vienna, Virginia is a software engineer for KOZ Inc who began programming in JavaScript with its first beta release. He has worked extensively with many Internet technologies while developing Internet telephony solutions at Lucent Technologies. His programming experience includes a variety of languages such as Java, C++, Smalltalk, Perl, HTML, XML, and Pascal. Ting holds degrees in Computer Engineering and Electrical Engineering from North Carolina State University.
Sean Michaels is a software engineer at Avesair, Inc. where he designs and implements next generation mobile commerce applications. He has been in the Internet space since 1994 and has a depth of experience in developing highly distributed fault tolerant applications. He has used Java, C++, and XML extensively over the years. Previously, he coauthored the Official Netscape ONE book and the Official Netscape Technologies Developer Guide from Netscape Press. Michaels holds a degree in Latin from Millsaps College in Jackson, MS and a degree in Computer Science from Mississippi College.
This one is for my sisters: Sandra, Valerie, and Evelyn. They truly are inspirations in my life and have broadened my visions and provided support well beyond anything I would have ever imagined. I love each of you very much.
—R. Allen Wyke
I dedicate this book to my wonderful wife, Deena, who is the greatest! Your constant encouragement, love, and support has carried me through the writing of this book. I love you!
—Jason D. Gilliam
This book is dedicated to my family: John, Alice, Angela, Melissa, Olivia, and Tilly. Thank you for all your love and support for everything I’ve done in my life. I love you all very much.
—Charlton Ting
I would like to dedicate this book to my wife April and my two children Noah, and Anna, and to the memory of my father Alan Michaels without whose influence I would not be here today.
—Sean Michaels
R. Allen Wyke
On the publishing side, I would like to thank Bob Kern of TIPS Publishing and my coauthors, Jason and Chuck, for their professionalism, hard work, and overall support in the proposing and writing of this book. I would also like to thank Shelley Johnston-Markanday, who has been nothing short of an absolutely fabulous acquisitions editor, and Jon Steever, who developed the book and kept us focused. Additionally, I would like to thank everyone at Sams who worked on the book and helped make sure that was the best it could be.
I would also like to thank Dan Jaye for the professional opportunities he has allowed me to pursue at Engage, as well as the pressure to push the envelope a little more. And finally, I would like to thank the wonderful woman in my life, J, and the rest of the “Raccoons.” It’s never a dull moment around any of you.
Jason D. Gilliam
I would like to thank Bob Kern of TIPS Publishing and my coauthors, Allen and Chuck, for their efforts in developing and writing this book. I would also like to thank our acquisitions editor, Shelley Johnston-Markanday, and development editor, Jon Steever, for all their hard work as well as everyone at Sams who helped make this book a success.
I would also like to thank the “lunch guys” for their open ears and words of encouragement.
I would like to thank Bob Kern of TIPS Publishing for all his hard work in making this book possible. I also want to thank my coauthors, Allen and Jason, for all their hard work, dedication, and encouragement to bring this book together and make it such a great success. It’s truly an honor to work with you guys. Additionally I would like to thank Shelley Johnston-Markanday, Scott Meyers, Jon Steever, and everyone at Sams who worked so hard at making this book so successful.
I also want to thank all my friends who have been there when I needed them: Mike, Carolyn, Monty, Theresa, Mitch, Sabrina, John O, Sunil “the Z Doc” Cherukuri, Blanke, Cosima, Nairn, Airmer Roberts, and anyone I may have forgotten to mention. You guys are the greatest friends anyone could have.
Sean Michaels
I would like to thank Bob Kern at TIPS Publishing for putting up with my antics during the authoring process. Also, the coauthors: Allen, Chuck, and Jason for giving me a solid foundation to work with and making the first edition of this book successful. I would also like to thank the folks at Sams Publishing: Shelley Johnston-Markanday, Scott Meyers, and Jon Steever for guiding the book through the process.
As the reader of this book, you are our most important critic and commentator. We value your opinion and want to know what we’re doing right, what we could do better, what areas you’d like to see us publish in, and any other words of wisdom you’re willing to pass our way.
You can e-mail or write me directly to let me know what you did or didn’t like about this book—as well as what we can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of this book, and that due to the high volume of mail I receive, I might not be able to reply to every message.
When you write, please be sure to include this book’s title and author as well as your name and phone or fax number. I will carefully review your comments and share them with the author and editors who worked on the book.
Fax: | 317-581-4770 |
Email: | |
Mail: | Mark Taber |
Welcome to Pure JavaScript, 2nd Edition! This book has been written by JavaScript programmers for JavaScript programmers, and has been updated to cover the most current version of the language. It is your complete reference for developing, testing, and deploying JavaScript solutions in pages and on Web sites.
Pure JavaScript was not written to teach a person how to program, but rather to provide the details and semantics of the JavaScript language so programmers can exploit it as they see fit. JavaScript has evolved over the past few years and is reaching into new areas, especially in the most current browsers and server-side environments, most of which are addressed in this book. The book itself is broken into three main parts, including references on concepts, techniques, and syntax. Each represents a valuable step in learning and using the language.
Part I, “A Programmer’s Overview of JavaScript,” acts as a bridge for programmers who are currently programming in another language. It covers some programming techniques, such as the use of regular expressions, event handlers, exceptions, and even debugging. Many times programmers don’t want to buy a beginners book on JavaScript because they do not need to know how to program, but rather they need specifics about the language. When they know these specifics and semantics, the syntax is easy. This section provides the necessary information for such a programming migration.
Part II, “Programming in JavaScript,” shows you the advantages and strengths of JavaScript. It discusses some of the pros and cons of using the language on the client-side, server-side, and even within the Windows Script Host environment. Programmers will learn how to use JavaScript in real-world instances. They will be introduced to some of the browser issues as well as how to process Web information. In addition, programmers will be shown how to access Java functions within an applet and to use server-side JavaScript for Internet, intranet, or extranet development. After you have completed this section, you will be ready to move forward and start programming. This leads you into the last section of the book.
Part III, “JavaScript Reference,” makes up the majority of the book and contains some of the most useful information for current JavaScript programmers—reference material organized by object. Each property, method, and event is discussed in detail under its associated object; and you’ll see an example of its use. Each entry also shows the appropriate language version and environment (browser, server, and so on) support.
The section itself is broken into nine chapters. The first chapter covers the core JavaScript objects and syntax. The next chapter covers objects specific to the client-side, which is where JavaScript really has its roots. The third, fourth, fifth, and sixth chapter in this section outlines the various support for the Document Object Model (DOM) within JavaScript. The seventh chapter covers server-side JavaScript objects for the Netscape and iPlanet Enterprise servers, and the Active Server pages (ASP) environment present in Microsoft’s IIS Web Servers. The second to last chapter in the section covers the JScript RunTime objects, and the final chapter covers Windows Script Host.
And that covers it! For new JavaScript programmers, welcome to the world of JavaScript. For those of you wanting a good, solid reference for your programming needs, we hope you find this book to be the most resourceful and current title on the shelves today!
R. Allen Wyke
Jason Gilliam
Charlton Ting
Sean Michaels
18.119.131.72