sams pure javascript (1999)

1.4K 113 0
sams pure javascript (1999)

Đ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

Release Team[oR] 2001 [x] java - 2 - Pure JavaScript by R. Allen Wyke, Jason D. Gilliam and Charlton Ting ISBN: 0672315475 Sams © 1999, 1448 pages This useful reference provides extensive code and comments to show JavaScript developers how their code will work on real Web pages. Table of Contents Back Cover Synopsis by Rebecca Rohan Reference-style syntax manuals seldom set up the code for an entire HTML page to demonstrate individual entries, but Pure JavaScript does just that. It uses thorough, well-commented example code to leave little doubt how to make the syntax work on a real page. The book takes the "actually working" idea even further by providing tables of syntax support in Navigator 2.0, 3.0, 4.0-4.05, 4.06-4.5, and 5.0; Internet Explorer 3.0, 4.0, and 5.0; and Opera 3.0 and 3.5. Server-side JavaScript gets attention, without muddying the waters with Microsoft's IIS scripting engine or Active Server Pages (ASP). If you want strong backup for implementing proper JavaScript, and need to know which efforts will reach the visitors to your pages, this book should prove useful. - 3 - Table of Contents PureJavaScript - 4 About the Authors - 6 Dedications - 6 Acknowledgments - 6 Tell Us What You Think! - 7 Introduction - 8 Part I A Programmer’s Overview of JavaScript Chapter 1 - What Is JavaScript to a Programmer? - 8 Chapter 2 - Details of the Language - 25 Chapter 3 - Server-Side JavaScript - 86 Part II Programming in JavaScript Chapter 4 - The JavaScript Runtime Environment - 103 Chapter 5 - Forms, Cookies, Windows, and Layers - 129 Part III JavaScript Reference by Object Chapter 6 - Core Syntax - 159 Chapter 7 - Client-Side Browser Syntax - 446 Chapter 8 - Netscape’s Server-Side Additions - 1054 Chapter 9 - Microsoft’s Scripting Engine Extensions - 1199 Part 4 Appendixes Appendix A - Navigator-Supported Syntax - 1331 Appendix B - Internet Explorer-Supported Syntax - 1368 Appendix C - Opera-Supported Syntax - 1395 Appendix D - ECMAScript Standard Syntax - 1415 Appendix E - Server-Side JavaScript Syntax Support - 1422 Appendix F - JavaScript Resources - 1436 Back Cover Pure JavaScript is a premium reference for experienced JavaScript programmers. It contains concise descriptions of JavaScript forms, cookies, windows, and layers. It also includes an accelerated introduction to JavaScript concepts and components. Beyond the brief descriptions and short syntax snippets found in most references, this book provides real-life, well-commented JavaScript examples for each documented object, property, method, and event handler. This not only helps your understanding of the syntax, but also provides a contextual aid in determining how and why a specific object or method may be used. Pure JavaScript also includes: • A special reference section dedicated to server-side JavaScript • Coverage of JScript and Microsoft's Active Scripting • A complete reference to browser-supported JavaScript, including support for Netscape Navigator, Microsoft Internet Explorer, and Opera - 4 - About the Authors Jason D. Gilliam, a software engineer at KOZ.com in the Research Triangle Park, NC, has developed many intranet Web pages and CGI programs as well as numerous C++ GUI applications and database connectivity programs. He holds a bachelor's degree in Computer Engineering from North Carolina State University. When not at work, Jason creates Windows-based audio programs and composes original music using PCs. Charlton Ting of Vienna, VA, is a software engineer for Lucent Technologies and develops Internet telephony solutions for leading Internet companies. He has created numerous applications and Web sites using Java, JavaScript, CGI, CORBA, and HTML technologies. Charlton holds bachelor's degrees in Computer Engineering and Electrical Engineering from North Carolina State University. R. Allen Wyke, Practice Manager of System Integration Consultants at Engage Technologies, has developed intranet pages and Internet sites for several leading companies. His writing experience includes co-authoring The Perl 5 Programmer's Reference, The Official Netscape Navigator 4 Book, as well as contributing to two additional books on HTML (The HTML 4 Programmer's Reference and HTML Publishing for the Internet, 2nd Edition). He has also worked on another book that contains a section on Internet resources, and is designed for college graduates. PureJavaScript Jason Gilliam Charlton Ting R. Allen Wyke Copyright © 1999 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 authors assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. International Standard Book Number: 0-672-31547-5 Library of Congress Catalog Card Number: 99-62353 Printed in the United States of America First Printing: August 1999 4 3 2 1 - 5 - Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams 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 authors 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. Acquisitions Editor Randi Roger Development Editor Scott D. Meyers Managing Editor Lisa Wilson Project Editor Rebecca Mounts Copy Editor Pat Kinyon Indexer Heather Goens Proofreader Cynthia Fields Technical Editors A ndrew Wooldridge Nate Kassenbaum Interior Design Karen Ruggles Cover Design - 6 - A nne Jones Copy Writer Eric Borgert Layout Technician Brad Lenser About the Authors Jason D. Gilliam, a software engineer at KOZ.com in the Research Triangle Park, NC, has developed many intranet Web pages and CGI programs as well as numerous C++ GUI applications and database connectivity programs. He holds a bachelor’s degree in Computer Engineering from North Carolina State University. When not at work, Jason creates Windows-based audio programs and composes original music using PCs. Charlton Ting, of Vienna, VA, is a software engineer for Lucent Technologies and develops Internet telephony solutions for leading Internet companies. He has created numerous applications and Web sites using Java, JavaScript, CGI, CORBA, and HTML technologies. Charlton holds bachelor’s degrees in Computer Engineering and Electrical Engineering from North Carolina State University. R. Allen Wyke, Practice Manager of System Integration Consultants at Engage Technologies, has developed intranet pages and Internet sites for several leading companies. His writing experience includes co-authoring The Perl 5 Programmer’s Reference, The Official Netscape Navigator 4 Book, as well as contributing to two additional books on HTML (The HTML 4 Programmer’s Reference and HTML Publishing for the Internet, 2nd Edition). He has also worked on another book that contains a section on Internet resources, and is designed for college graduates. Dedications —Jason D. Gilliam —Charlton Ting —R. Allen Wyke Acknowledgments I would like to thank Bob Kern of TIPS Publishing and my co-authors, Allen and Chuck, for their efforts in developing and writing this book. I would also like to thank our Acquisitions Editor, Randi Roger and Development Editor, Scott Meyers, for all of their hard work as well as everyone at Sams who helped make this book possible. I would also like to thank the “lunch guys” for their open ears and words of encouragement. —Jason D. Gilliam - 7 - 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 co-authors, Allen and Jason, for all their hard work, dedication, and encouragement to make this book a success. Additionally I want to thank our Acquisitions Editor Randi Roger, Scott Meyers, and everyone at Sams who worked so hard at making this book possible. I also want to thank all my friends who provided so much support during the rough times: Mike, Carolyn, Monty, Theresa, John, Blanke, Stacey, the doc, and anyone I may have forgotten to mention. You guys are the greatest friends anyone could have. —Charlton Ting On the publishing side, I would like to thank Bob Kern of TIPS Publishing and my co- authors, 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 Randi Rogers, who has been nothing short of an absolutely fabulous Acquisitions Editor, and Scott Meyers, 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 it was the best it could be. I would also like to thank Beth Roach and Dan Peterson for allowing me the flexibility and opportunity to write during all my work and travel. I want to say thanks to little Miss Wendy as well. She has provided a VERY honest perspective on many things as of late and helped keep me in line. And finally, I would like to thank the “Raccoons.” You have made the last six months the happiest of my life. —R. Allen Wyke Tell Us What You Think! 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 fax, email, 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 authors as well as your name and phone or fax number. I will carefully review your comments and share them with the authors and editors who worked on this book. Fax: 317-581-4770 Email: internet_sams@mcp.com Mail: Mark Taber Associate Publisher Sams Publishing 201 West 103rd Street Indianapolis, IN 46290 USA - 8 - Introduction Welcome to Pure JavaScript! This book has been written by JavaScript programmers for JavaScript programmers. 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, many 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 a language. Part I of the book, “A Programmer’s Overview of JavaScript,” acts as a bridge for programmers who are currently programming in another language. Many times programmers don’t want to buy a beginner’s book on JavaScript because they do not need to know how to program, but rather they need specifics about the language. Once 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 and the environments in which it is interpreted. 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. Programmers will even 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 by Object,” 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 browser or server support. The section itself is broken into four chapters. The first chapter covers JavaScript standard objects and syntax. The next chapter covers client-side and browser scripting objects. The third chapter covers server-side JavaScript objects (primarily for Netscape Enterprise servers). Finally, we cover JavaScript geared for Microsoft Active Scripting interface. In addition, several appendixes have been included. Located here are quick reference tables to find browser and version support of the syntax. There is also an appendix, “JavaScript Resources,” that includes JavaScript Web resources for additional documentation and help with programming issues that you may come across. A nd 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, 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 Part I: A Programmer's Overview of JavaScript - 9 - Chapter List Chapter 1: What is JavaScript to a Programmer? Chapter 2: Details of the Language Chapter 3: Server-Side JavaScript Chapter 1: What Is JavaScript to a Programmer? Overview In the beginning, there were Assembly and compiled languages. Later came scripting languages such as sed, awk, and Perl, which many programmers used to perform a variety of tasks. These were followed by, in the late 80s and early 90s, the Internet, which exploded into a technological revolution that allowed anyone with a modem to communicate and retrieve information from around the world. As the Internet grew in number of users, it was obvious that an increase in functionality was needed in the browsers being used and in the data they were rendering. HTML, even with its advantages, was falling short of providing the control many developers wanted when creating Web pages and applications. This prompted the use of server-side programs to handle some of the page dynamics developers needed from their sites. These programs helped Web developers by allowing them to increase a site’s functionality and to process user-submitted information. However, CGI, or Common Gateway Interface, program had to generate a response that told the user to resubmit a request when he or she sent incorrect or incomplete information. This led to a lot of back- and-forth data transmission between a browser and a server. But, overall, it was a minor price to pay for the functionality received. It became increasingly obvious that client-side intelligence was needed to replace some of the CGI functionality and error checking and decreasing the amount of time a user spent connecting to a server. This would also allow the Web site to offload some of its processing load to the browser machine, which meant an increase in the overall performance of a site. It was partially this lack of client-side functionality and efficiency that helped spawn a new scripting language—one that could be executed within a browser’s environment and not on the server. This language could be used to perform some client-side tasks such as form validation and dynamic page content creation—one that would put the programming into HTML publishing. Welcome to the birth of JavaScript. On December 4, 1995, Netscape and Sun jointly introduced JavaScript 1.0, originally called LiveScript, to the world. This language, unlike its server-based predecessors, could be interpreted within the new Netscape Navigator 2 browsers. As an interpreted language, JavaScript was positioned as a complement to Java and would allow Web developers to create and deploy custom applications across the enterprise and Internet alike. JavaScript gave developers the power to truly program—not just format data with HTML. In addition to the client-side control developers desired, Netscape implemented server- - 10 - side JavaScript. This allowed developers to use the same programming language on the server as they did in their pages for browsers. Database connection enhancements were added to the language (called LiveWire) allowing the developer to pull information directly from a database and better maintain user sessions. JavaScript had truly bridged the gap between the simple world of HTML and the more complex CGI programs on the server. It provided a common language for Web developers to design, implement, and deploy solutions across their networks and distributed the overall processing load of their applications. The next level of acceptance in the world of JavaScript was Microsoft’s implementation of the language in its Internet Explorer 3 browser—its interpretation of the language was called JScript. Like Netscape, Microsoft also implemented the language on the server- side (JScript 2.0) that was done in tandem with its ASP, or Active Server Pages, technology. JavaScript Versus JScript, and what is ECMAScript? JScript was based on the published documentation from Netscape, so it should have been the same thing as JavaScript 1.0. However, there were a few “features” that Netscape did not publish, as well as some functionality that was not re-created by Microsoft correctly. The result of this is that there are some discrepancies between JScript 1.0 and JavaScript 1.0 in Microsoft’s first generation releases. Since the release of these initial browsers, JavaScript was submitted and has become a standard, known as ECMAScript 1.0 (ECMA-262), with the European Computer Manufacturers Association (ECMA). Because of this standardization, it is now perceived that JavaScript is Netscape’s implementation of ECMAScript and JScript is Microsoft’s implementation. The adoption of ECMAScript 1.0 occurred in June 1997 followed by its adoption by the International Organization for Standardization and International Electrotechnical Commission in April 1998 (ISO/IEC 16262). ECMAScript 2.0 was approved by ECMA in June 1998 and is on its path for complete adoption by these standards’ bodies. Note Since ECMAScript was standardized after Netscape’s JavaScript, this book will refer to it as JavaScript. So, what is JavaScript to the programmer? Well, in its purest form it is an object based, cross-platform, loosely-typed, multi-use language that allows a programmer to deploy many types of solutions to many clients. It not only involves adding functionality to Web pages as rendered within a browser, it also allows server-side processing for Netscape and Microsoft Web servers. JavaScript has also most recently been included in Microsoft’s Windows Scripting Host to allow programmers to write scripts to be executed on the operating system itself. This functionality is similar to the old DOS batch files, but gives programmers more functionality and versatility in what they can accomplish. It is this type of advancement that has allowed the language to take hold in the computer world and continue to progress. In addition to the benefits of these environments where JavaScript can be executed, there are security measures in place to protect end users against malicious code. Even though it is still young in terms of age, JavaScript, in its current version, is very mature and powerful. It is this functionality, ability, and versatility that positions JavaScript as the [...]... of JavaScript supported by the browser, use the format It is also possible to force the interpreter to use different versions of JavaScript (, for example) Note Currently, if the LANGUAGE attribute is left out of the tag, Navigator and Internet Explorer will assume the most current version of JavaScript should be used Comments JavaScript. .. at 0 and goes up Also, JavaScript supports having arrays within arrays, called multidimensional arrays The implementation of arrays in JavaScript has been changing ever since JavaScript was introduced The original implementation of arrays in JavaScript 1.0 were not really arrays at all but rather JavaScript objects with multiple property settings A true Array object was added in JavaScript 1.1, and additional... properties in a frame served from http://myscripts.purejavascript.com from another frame that was delivered from http://mydocs.purejavascript.com Even though the domain is the same, the complete URL is not To get around this minor situation, programmers can set the document.domain property to the suffix of the current domain This will allow them to access JavaScript properties on pages served from other... please see the Client-Side JavaScript Guide on Netscape’s DevEdge (http://developer.netscape.com) site There is an entire section (“Using Data Tainting in JavaScript 1.1”) in the JavaScript Security” chapter devoted to security and the concepts of data tainting Because data tainting did not provide the true security model JavaScript needed, Netscape removed its functionality in JavaScript 1.2 and replaced... prevent JavaScript from working the way it was programmed Before programming in JavaScript, you should first try to understand any documented bugs that exist Doing so can save you hours of debugging in the long run Try to determine if you really need to use JavaScript on a given page as well Ask yourself if you are using it to add functionality to the page or just make its appearance better JavaScript. .. support JavaScript within the body of an email message This makes it possible for a user to send HTML emails containing JavaScript that is interpreted when the recipient reads the message As a programmer, you need to keep in mind an email application is not a browser Users are very particular about what they experience in their messages, and overuse of JavaScript could lead to annoying your recipients JavaScript. .. code can enable this feature: document.domain = “purejavascript.com”; Setting this property will allow you to access the other sub-domains within your domain When JavaScript 1.1 was released in Navigator 3.0, Netscape implemented a more complete security solution referred to as data tainting In addition to the security model in the first generation JavaScript browsers, data tainting allowed the user... to be placed in front of the HTML > comment closer because JavaScript will misinterpret > as a pre-decrement operator Data Types and Variables Before diving into JavaScript operators, conditionals, and loops, one should understand JavaScript data types and variables These are building blocks that will be important going forward Fortunately, JavaScript kept its implementation of data types simple and... prototyping new properties To get an idea of how this is done, take a look at JavaScript object orientation Object Orientation of JavaScript Before we go into a lot of detail on the object orientation of JavaScript, first look at some differences in the core components and functionality between server-side and client-side JavaScript Both have objects that are specific to their runtime environment, so... Understanding the hierarchy of the JavaScript objects is a very important item if you plan on doing any in-depth programming You will get a better understanding of how parent and child objects interact as well as how they are referenced To help with this understanding Figure 1.1 gives a graphical representation of the basic client-side JavaScript hierarchy Figure 1.1: Client-side JavaScript object hierarchy . Appendix E - Server-Side JavaScript Syntax Support - 1422 Appendix F - JavaScript Resources - 1436 Back Cover Pure JavaScript is a premium reference for experienced JavaScript programmers What Is JavaScript to a Programmer? - 8 Chapter 2 - Details of the Language - 25 Chapter 3 - Server-Side JavaScript - 86 Part II Programming in JavaScript Chapter 4 - The JavaScript. Welcome to Pure JavaScript! This book has been written by JavaScript programmers for JavaScript programmers. It is your complete reference for developing, testing, and deploying JavaScript solutions

Ngày đăng: 28/04/2014, 17:06

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan