ebook img

JavaScript Step By Step PDF

530 Pages·2011·8.772 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview JavaScript Step By Step

JavaScript Step by Step, Second Edition Steve Suehring Editor Russell Jones Copyright © 2010 Steve Suehring Complying with all applicable copyright laws is the responsibility of the user. All rights reserved. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without express written permission of O’Reilly Media, Inc. 1 2 3 4 5 6 7 8 9 M 5 4 3 2 1 0 Microsoft Press titles may be purchased for educational, business or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]. Visit our website at microsoftpress.oreilly.com. Send comments to [email protected]. Microsoft, Microsoft Press, ActiveX, Excel, FrontPage, Internet Explorer, PowerPoint, SharePoint, Webdings, Windows, and Windows 7 are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the author, O’Reilly Media, Inc., Microsoft Corporation, nor their respective resellers or distributors, will be held liable for any damages caused or alleged to be caused either directly or indirectly by such information. Acquisitions and Development Editor: Russell Jones Production Editor: Holly Bauer Production Services: Online Training Solutions, Inc. Technical Reviewer: Michael Bazarewsky Indexing: Potomac Indexing, LLC Cover: Karen Montgomery Illustrator: Robert Romano Microsoft Press To Chris --Steve Suehring A Note Regarding Supplemental Files Supplemental files and examples for this book can be found at http://examples.oreilly.com/0790145302243-files/. Please use a standard desktop web browser to access these files, as they may not be accessible from all ereader devices. All code files or examples referenced in the book will be available online. For physical books that ship with an accompanying disc, whenever possible, we’ve posted all CD/DVD content. Note that while we provide as much of the media content as we are able via free download, we are sometimes limited by licensing restrictions. Please direct any questions or concerns to [email protected]. Acknowledgements Every time I write a book, I get mired in a futile attempt to thank everyone who has helped make it possible. I originally thought that I should thank everyone and their respective families in case I never wrote a book again. But now that I’ve written several books, some of them twice, there seems to be less urgency to thank everyone. It’s not that people need to be thanked less or that I did this all myself —far from it. But inevitably I always forget to thank someone, and though they may not be offended (who cares, it’s just a technology book), I still feel bad. And yet as I sit here and write these acknowledgements, I still want to thank some people. As always, this is in no particular order and the list is incomplete. Obviously, thank you to Rebecca and Jakob and my family, who support the 16 to 20 hour days involved in getting a book written in a short time. Thanks to Russell Jones at O’Reilly for his editing and encouragement throughout, and thanks to Neil Salkind at Studio B as well. Thanks to Chris Tuescher, John Hein, Jeremy Guthrie, and Jim Leu, Andy Berkvam, Dan Noah, Justin Hoerter, and Mark Little. All those individuals told me that when I thank them in a book they feel compelled to buy a copy. (If it worked like that for everyone, I’d go get the phone book.) While I’m fishing for people to thank, I should thank Jason, Kelly, John, and Jeff as well as the web team and all my coworkers. Thanks to brother Bob for helping me choose music to write by. Thanks as well to Jim Oliva and John Eckendorf. More than one Saturday morning was spent listening to the radio while writing, and it made working on a Saturday morning less painful. Thank you to Tim and Rob at Partners, Pat Dunn, and Dave Marie as well. Thank you to Jeff Currier for putting a door on my office. Thank you also to the readers who sent feedback for the first edition of the book. That helped in shaping some of the areas to highlight in this second edition. After rereading these acknowledgements, I realize I should have just thanked everyone using first names. That would give plausible deniability: “Yes, when I thanked John, I really meant you and not the other one.” I think there was someone else that I promised to thank, too, but I can’t recall who, but thank you, too. Introducing JavaScript Step by Step, Second Edition Much has changed since the first edition of JavaScript Step by Step was written in 2007. The underlying JavaScript specification received a major update; Microsoft released Windows Internet Explorer 8—and now 9 (which is about to be released as I write this); JavaScript development frameworks have matured and are now ubiquitous; and browsers other than Internet Explorer and Firefox, such as Safari, Chrome, and mobile browsers, became much more popular. This second edition of JavaScript Step by Step builds on the foundation laid down by the first edition. The underlying architecture of the JavaScript language is largely the same, but its use has become pervasive, increasing hugely even in just the last three years. With that in mind, the layout and coverage of the book have also remained largely the same, with two notable exceptions: this edition places a much greater emphasis on JavaScript event handling, and it includes an entirely new section covering JavaScript libraries. Specifically, the book focuses on jQuery, which can help simplify JavaScript development, especially on large projects. Throughout the book, you’ll find highlights and additions for the new features in the latest version of JavaScript. Also, the examples used in the book received greater scrutiny, in multiple browsers, to reflect the reality of today’s web landscape. Reader feedback from the first edition is reflected in the content and was the impetus for adding jQuery and emphasizing event handling. The introduction to the first edition is still relevant and applicable, and so I’ve included it here. JavaScript is an integral language for web application development, regardless of whether you’re adding interactivity to a web page or creating an entire application. Today’s web wouldn’t be the same without JavaScript. JavaScript is a standards-based language with a formal specification; however, as any web developer will tell you, almost every web browser interprets that specification differently, which makes web developers’ jobs more difficult. Fortunately, most web browsers are converging in their support and interpretation of JavaScript’s core functions. This book provides an introductory look at JavaScript, including some of its core functions as well as newer features and paradigms, such as Asynchronous JavaScript and XML (AJAX). Today’s web users rely on many different platforms and many different browsers to view web content. This fact was central to development of every aspect of the book, so you’ll see screenshots in multiple browsers and an emphasis on standards-based, rather than proprietary, JavaScript development. The first part of the book examines JavaScript and helps you get started developing JavaScript applications. You don’t need any specific tools for JavaScript development, so you see how to create JavaScript files in Microsoft Visual Studio, in Eclipse, and even in Notepad (or any text editor). Next, the book examines JavaScript’s core language and functions, followed by an exploration of the relationship between JavaScript and the web browser. Finally, you see AJAX demonstrated and see how to build dynamic search forms. The final part of the book highlights JavaScript frameworks and libraries, giving specific focus to jQuery and jQuery UI. Who Should Read This Book? This book is for beginning JavaScript programmers—people who are interested in learning the basics of modern JavaScript programming: the language syntax, how it works in browsers, what the common cross-browser problems are, and how to take advantage of AJAX and third-party libraries such as jQuery to add interactivity to your web pages. Features and Conventions of This Book This book takes you step by step through the process of learning the JavaScript programming language. Starting at the beginning of the book and following each of the examples and exercises provides the maximum benefit to help you to gain knowledge about the JavaScript programming language. If you already have some familiarity with JavaScript, you might be tempted to skip the first chapter of this book. However, Chapter 1, details some of the background history of JavaScript as well as some of the underlying premise for this book, both of which might be helpful in framing the discussion for the remainder of the book. Chapter 2, shows you how to get started with programming in JavaScript. If you’re already familiar with web development, you might already have a web development program, and therefore you might be tempted to skip Chapter 2 as well. Nevertheless, you should become familiar with the pattern used in Chapter 2 to create JavaScript programs. The book contains a Table of Contents that will help you to locate a specific section quickly. Each chapter contains a detailed list of the material that it covers. In addition, you can download the source code for many of the examples shown throughout the book. Convention Meaning Lists Step-by-step exercises are denoted by procedural lists with steps beginning with 1. See Also These paragraphs point you to other sources of information about a specific topic. Tip/Note/Important Tips and notes feature additional bits of information that might be helpful for a given subject. Inline Code Inline code—that is, code that appears within a paragraph—is shown in italic font. Code Blocks Code blocks are shown in a different font to highlight the code. What’s in the Companion Content The downloadable companion content included with this book contains all the important source code from the examples and exercises shown throughout the book. The download consists of projects and files laid out on a per-chapter basis—one directory for each chapter. Each chapter directory contains the step-by-step exercises used within that chapter. Because JavaScript is usually dependent on a surrounding web page, the source code for the step-by- step exercises has been split within the directories. This enables you to copy and paste much of the repetitive HTML and concentrate on entering the JavaScript into the example. Each chapter directory also contains a CompletedCode subdirectory that contains the entire example. You can open the files in the CompletedCode folder to see the examples as laid out in the chapter. Downloading the Companion Content Most of the chapters in this book include exercises that let you interactively try out new material you learn in the main text. All the sample projects and files are available for download from the book’s catalog page on the website for Microsoft’s publishing partner, O’Reilly Media, at: http://oreilly.com/catalog/9780735645523/ Click the Companion Content link on that page. Locate and download the file 9780735645523- files.zip. Unzip that file into a folder on your local drive.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.