What you are probably asking yourself is, "Can I really learn to program using JavaScript and JScript in a single weekend?" The answer is "Yes!" I am not promising that [r]
Trang 1Learn JavaScript In a Weekend, 2nd Edition is the ultimate guide to integrating JavaScript into Web pages With step-by-step instructions, readers will learn how to effectively use JavaScript, the most popular scripting language used for Web development today Setting itself apart from competitors, this is the only beginner-level book to cover both JavaScript and Jscript The author includes an introduction to computer and network automation using JScript To enforce the material covered throughout the book, there are a number of new scripts introduced and available for download on the book's companion Web site
Features
• Covers the most current versions of JavaScript (Version 1.5) and JScript (Version 5.6) Much of the competition still focuses on previous versions of these languages
• Incorporates the latest versions of Netscape and Internet Explorer while much of the competition still focuses on previous versions of these browsers
• The author differentiates the book from its competition by also covering JScript and its role as a WSH scripting language JavaScript will entail about 70% of the book, while about 30% will be dedicated to JScript
• A JavaScript programming primer for beginning programmers and Web page developers will also be included
Trang 2• Table of Contents
Dedication
ABOUT THE AUTHOR
Introduction
What This Book Is About
Who Should Read This Book?
What You Need to Begin
How This Book Is Organized
Special Features of This Book
Chapter FRIDAY EVENING Introducing JavaScript and JScript
Introducing JavaScript and JScript
What Kinds of Things Can You Do with JavaScript and JScript?
A Little History Lesson
JavaScript and Browser Compatibility
Integrating JavaScript with HTML
JavaScript and Case Sensitivity
Different Ways to Integrate JavaScript into Your HTML Pages
Taking a Break
Introducing JScript
What's Next?
Chapter SATURDAY MORNING Learning the Basics of JavaScript Coding
A Few Words about Scripting
Working with Values
Take a Break
JavaScript and JScript Statements
Streamlining Your Scripts with Functions
Using Arrays
Object-Based Programming
Working with Built-In Objects
What's Next?
Chapter SATURDAY AFTERNOON Using JavaScript to Build Better Web Pages Working with Browser-Based Objects
A Brief Overview of Browser Object Models
Browser Objects
Creating Custom Objects
Handling Events
Take a Break
Using JavaScript to Manage Frames
Using JavaScript to Manage Forms
What's Next?
Chapter SATURDAY EVENING Doing Really Cool Things with Your Web Pages Controlling the Status Bar
Improving Browser Navigation
Trang 3Taking Advantage of Dialog Boxes
Take a Break
Working with Different Types of Browsers
Other Neat Stuff
Basic Graphics and Animation
What's Next?
Chapter SUNDAY MORNING Advanced JavaScript Coding
Baking JavaScript Cookies
Debugging Your JavaScripts
Take a Break
Overview of the On-line Bookmall Web Site
Crafting the Index Page
The Featured Book
Navigating the Bookmall
Finishing the Bookmall
Receiving Customer E-Mail
What's Next?
Chapter SUNDAY AFTERNOON Learning How to Use JScript and the WSH
An Overview of the WSH Object Model
JScript Runtime Objects
Take a Break
Working with the Windows File System
Opening and Closing Files
Creating Report and Log Files
Processing File Contents
Administering Files and Folders
What's Next?
Chapter SUNDAY EVENING Using JScript to Automate Windows Tasks Automating Windows Desktop Tasks
Executing Windows Commands
Working with Networks and Network Resources
Taking a Break
Interacting with the Windows Registry and Application Event Log
Automating Script Execution
What's Next?
What's on the Web Site?
Integrating JavaScript with HTML
Dedication
Trang 4To Alexander, William, Molly, and Mary.
ACKNOWLEDGMENTS
There are a number of individuals who deserve a lot of credit for the effort that they put into this book I especially want to thank Arlie Hartman who served as the book's acquisitions editor I also want to thank the book's project editor, Kim Benbow, for her guidance and suggestions Finally, I want to acknowledge the book's copy editor, Gene Redding, and its technical editor, Burt LaFontaine, as well as everyone else at Premier Press for all their hard work
ABOUT THE AUTHOR
Jerry Lee Ford, Jr is an author, educator, and an IT professional with over 15 years' experience in information technology, including roles as an automation analyst, technical manager, technical support analyst, automation engineer, and security analyst In addition, he has a master's degree in business administration from Virginia Commonwealth University in Richmond, Virginia Jerry is also the author of 13 other books including Learn VBScript In a Weekend, Microsoft Windows Shell Scripting and WSH Administrator's Guide, VBScript Professional Projects and Microsoft Windows XP Professional Administrator's Guide He has over five years' experience as an adjunct instructor teaching networking courses in information technology Jerry lives in Richmond, Virginia, with his wife, Mary, and their children William, Alexander, and Molly
Trang 5Congratulations on your decision to learn JavaScript and JScript JavaScript is a powerful scripting language that, when combined with HTML, allows you to create exciting and powerful Web pages You can use these Web pages to run a small business or to share information with family and friends over the Internet JScript is a Microsoft implementation of JavaScript that can be used as a scripting language for automating repetitive or complex desktop and system tasks
What you are probably asking yourself is, "Can I really learn to program using JavaScript and JScript in a single weekend?" The answer is "Yes!" I am not promising that you will become a programming guru in just a few days, but if you will dedicate a full weekend to this book and follow along with its examples, you will be able to write your own JavaScripts and JScripts In no time you will be able to make dramatic improvements to your Web pages as well as develop scripts that automate any number of Windows desktop tasks
Syntactically, JavaScript and JScript are virtually identical So by learning how to write JavaScripts, you are also learning how to work with JScript as well Where the two languages differ is in the environments in which they execute JavaScripts are embedded inside HTML pages and run by Web browsers JScripts, on the other hand, are written as plain text files that are executed directly from the Windows desktop by the Windows Script Host or WSH
As long as you have basic Windows skills and a good HTML background, you'll find that this book will provide you with all the information and examples you need to get up and running with both of these exciting scripting languages in a single weekend
What This Book Is About
This book is about learning how to write JavaScripts in order to create exciting Web sites
It is also designed to teach you how to leverage the skills and knowledge that you'll develop working with JavaScript in order to create JScripts that automate desktop tasks Basic experience with Windows and HTML is assumed The book provides the rest for you By the time the weekend is over, you will have learned how to do the following:
• Integrate JavaScripts into your Web pages
• Use JavaScript to take control of the browser status line
• Use JavaScript to display pop-up alert, prompt, and confirmation dialog boxes so that you can interact with your visitors
• Use JavaScript to add graphic effects to Web pages
• Use JavaScript to create Web page banners, clocks, and other animation effects
• Use JavaScript to validate forms and e-mail the contents of those forms to yourself
• Write JavaScripts that collect and save visitor information
Trang 612 If you selected the When I Log On option, you will be prompted to provide the following information:
o Enter the user name Sets the name of a user account whose security
privileges should be used when running the task
o Enter the password Sets the account's password.
o Confirm password Confirms the account's password.
Make your selections and click on Next, and then skip to step 14
13 The wizard then prompts you to provide the following information:
o Enter the user name Sets the name of a user account whose security
privileges should be used when running the task
o Enter the password Sets the account's password.
o Confirm password Confirms the account's password.
14 Click on Finish
Once created, the new scheduled task is stored in the Scheduled Tasks folder, as shown in Figure 7.20
What's Next?
Congratulations, you made it to the end of this book, and in doing so have learned
everything that you need to know to begin programming using both JavaScript and JScript In accomplishing this goal, you have gained the knowledge required to begin creating interactive Web pages and to start automating Windows tasks But don't stop now Think of this as the beginning and not the end of your programming education You can learn a lot more by surfing the Internet for Web sites that cover JavaScript and
Trang 7JScript Most important of all, start writing your own scripts There is no better way to learn than by doing Good luck!
What's on the Web Site?
To save you the time and effort required to re-key all of the examples that you have seen
in this book, copies of each script are available for download from
http://www.courseptr.com as shown in Figure D.1
Integrating JavaScript with HTML
I have organized the book's scripts into Zip files by chapter This way you'll be able to download only the scripts that you need However, if you prefer, you can download them all at once in a single Zip file as well In addition to the sample scripts for both JavaScript and JScript, you'll also find that any graphic images used by sample scripts in a given chapter have been included in that chapter's download file