Plug-in JavaScript 100 POWER SOLUTIONS Robin Nixon New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto Copyright © 2011 by The McGraw-Hill Companies. All rights reserved. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher. ISBN: 978-0-07-173862-0 MHID: 0-07-173862-2 The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-173861-3, MHID: 0-07-173861-4. All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefi t of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps. McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs. To contact a representative please e-mail us at [email protected]. Information has been obtained by McGraw-Hill from sources believed to be reliable. However, because of the possibility of human or mechani- cal error by our sources, McGraw-Hill, or others, McGraw-Hill does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from the use of such information. TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGrawHill”) and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms. THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MER- CHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill has no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise. J8M<?LE;I<;JF=?FLIJ GCL>$@E F=GIF>I8DD@E>K@D< These handy guides are packed with ready-to- run plug-ins you can use right away to create dynamic Web content. Every plug-in offers a full working solution for a result you can achieve immediately, using complete code you simply drop into your own programs. Valuable customization tips are also included in these practical resources. Robin Nixon is a developer and freelance tech- nical writer who has published more than 500 articles in magazines such as PC Plus, PCW, Web User, .net, PC Advisor, and PC Answers. Available everywhere computer books are sold, in print and ebook formats. For Julie About the Author Robin Nixon has worked with and written about computers since the early 1980s (his first computer was a Tandy TRS 80 Model 1 with a massive 4KB of RAM!). Since then, he has written in excess of 500 articles for many of the U.K.’s top computer magazines. Plug-in JavaScript is his sixth book. Robin lives on the southeast coast of England with his wife Julie, who is a trained nurse, and five children. He also finds time to foster three disabled children and works full time from home as a technical author. Also by Robin Nixon The PC Companion, Sigma Press, 1993, ISBN 978-150585138 The Amstrad Advanced User Guide, Sigma Press, 1993, ISBN 978-150585152 Learning PHP, MySQL, and JavaScript, O’Reilly, 2009, ISBN 978-0596157135 Ubuntu: Up and Running, O’Reilly, 2010, ISBN 978-0596804848 Plug-in PHP, McGraw-Hill Professional, 2010, ISBN 978-0071666596 About the Technical Editor Alan Solis has more than 30 years experience designing, writing, and maintaining software for companies ranging from small start-ups to large corporations. He currently designs and maintains websites and web applications using PHP, JavaScript, Java, and various relational databases. In his spare time, Alan enjoys creative writing and is a published short story and poetry author. Alan lives in the San Jose, California area with his wife, Cheryl. v Contents at a Glance 1 Making the Best Use of These Plug-ins ............................. 1 2 JavaScript, CSS, and the DOM ..................................... 13 3 The Core Plug-ins ................................................ 23 4 Location and Dimensions ......................................... 73 5 Visibility ........................................................ 97 6 Movement and Animation ........................................ 129 7 Chaining and Interaction .......................................... 177 8 Menus and Navigation ............................................ 211 9 Text Effects ...................................................... 257 10 Audio and Visual Effects .......................................... 289 11 Cookies, Ajax, and Security ........................................ 321 12 Forms and Validation ............................................. 339 13 Solutions to Common Problems .................................... 359 Index ........................................................... 385 v This page intentionally left blank Contents Acknowledgments . .å° . xxiii Introduction . .å° . xxv 1 Making the Best Use of These Plug-ins ............................. 1 Downloading and Installing Web Browsers . 2 Choosing a Program Editor . .å° . 3 Managing Ajax . .å° . 4 Older Versions of Microsoft Internet Explorer . 6 Emulating Internet Explorers 6 and 7 . 7 The Companion Website . .å° . 8 Including All the Plug-ins . .å° . 9 Including Single Plug-ins . .å° . 9 Where to Include the JavaScript . .å° 10 Cherry Picking Code Sections . .å° 10 Bug Fixing and Reporting . .å° . 10 Waiting Until the Web Page Has Loaded . 11 Summary . .å° . 12 2 JavaScript, CSS, and the DOM ..................................... 13 The Document Object Model (DOM) . 14 Accessing the DOM from JavaScript . 16 Cascading Style Sheets . 17 Accessing Styles in JavaScript . .å° 19 JavaScript and Semicolons . .å° . 21 Summary . .å° . 21 3 The Core Plug-ins ................................................ 23 Plug-in 1: O() . .å° . 24 About the Plug-in . .å° . 24 Variables, Arrays, and Functions . 24 How It Works . .å° . 25 How To Use It . .å° . 30 The Plug-in . .å° . 31 Plug-in 2: S() . .å° . 31 About the Plug-in . .å° . 32 Variables, Arrays, and Functions . 32 How It Works . .å° . 33 How To Use It . .å° . 33 The Plug-in . .å° . 34 vii viii Plug-in JavaScript: 100 Power Solutions Contents ix Plug-in 3: Initialize() . .å° . 35 About the Plug-in . .å° . 35 Variables, Arrays, and Functions . 36 How It Works . .å° . 36 How To Use It . .å° . 39 The Plug-in . .å° . 39 Plug-in 4: CaptureMouse() . .å° . 40 About the Plug-in . .å° . 40 Variables, Arrays, and Functions . 41 How It Works . .å° . 41 How To Use It . .å° . 41 The Plug-in . .å° . 43 Plug-in 5: CaptureKeyboard() . .å° 43 About the Plug-in . .å° . 43 Variables, Arrays, and Functions . 44 How It Works . .å° . 44 How To Use It . .å° . 44 The Plug-in . .å° . 45 Plug-in 6: FromKeyCode() . .å° . 45 About the Plug-in . .å° . 46 Variables, Arrays, and Functions . 46 How It Works . .å° . 46 How To Use It . .å° . 46 The Plug-in . .å° . 47 Plug-in 7: GetLastKey() . .å° . 48 About the Plug-in . .å° . 48 Variables, Arrays, and Functions . 48 How It Works . .å° . 48 How To Use It . .å° . 48 The Plug-in . .å° . 49 Plug-in 8: PreventAction() . .å° . 49 About the Plug-in . .å° . 50 Variables, Arrays, and Functions . 50 How It Works . .å° . 50 How To Use It . .å° . 51 The Plug-in . .å° . 52 Plug-in 9: NoPx() and Px() . .å° . 52 About the Plug-ins . .å° . 53 Variables, Arrays, and Functions . 53 How They Work . .å° . 53 How To Use Them . .å° . 53 The Plug-ins . 54 Plug-in 10: X() and Y() . .å° . 54 About the Plug-ins . .å° . 55 Variables, Arrays, and Functions . 55 viii Plug-in JavaScript: 100 Power Solutions Contents ix How They Work . .å° . 55 How To Use Them . .å° . 55 The Plug-ins . 56 Plug-in 11: W() and H() . .å° . 56 About the Plug-ins . .å° . 57 Variables, Arrays, and Functions . 57 How They Work . .å° . 57 How To Use Them . .å° . 58 The Plug-ins . 59 Plug-in 12: Html() . .å° . 59 About the Plug-in . .å° . 60 Variables, Arrays, and Functions . 60 How It Works . .å° . 60 How To Use It . .å° .
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages433 Page
-
File Size-