[ Pobierz całość w formacie PDF ]
The Book of JavaScript: A Practical Guide to Interactive Web Pages
by thau!
ISBN: 1886411360
No Starch Press
© 2000 (397 pages)
A tutorial on JavaScript procedures.
Table of Contents
Automatically
Chapter 3
- Give the Browsers What They Want
Chapter 4
- Rollovers: Everyone’s Favorite JavaScript Trick
Chapter 5
- Opening and Manipulating Windows
Chapter 6
- Getting Functional: Writing Your Own JavaScript Functions
Chapter 7
- Giving and Taking Information with Forms
Chapter 8
- Keeping Track of Information with Arrays and Loops
Chapter 9
- Timing Events
Chapter 10
- Frames and Image Maps
Chapter 11
- Validating Forms, Massaging Strings, and Working with CGI
Chapter 12
- Cookies
Chapter 13
- Dynamic HTML
Chapter 14
- How to Fix Broken Code
Appendix A
- Beyond the Browser: Plug-ins, ActiveX, Making Music, and Java
Appendix B
- Reference to JavaScript Objects and Functions
Appendix C
- Answers to Assignments
Index
List of Figures
List of Tables
The Book Of Javascript— A Practical Guide
to Interactive Web Pages
thau!
No Starch Press
San Francisco
All rights reserved. No part of this work may be reproduced or transmitted in any form or
by any means, electronic or mechanical, including photocopying, recording, or by any
information storage or retrieval system, without the prior written permission of the
copyright owner and the publisher.
Printed in the United States of America
3 4 5 6 7 8 9 10—03 02 01
Trademarked names are used throughout this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, we are using the names only in
The Book Of Javascript— A Practical Guide to Interactive Web Pages
Foreword
Preface
Chapter 1
- Welcome to JavaScript!
Chapter 2
-
Using Variables and Built-in Functions to Update Your Web Pages
an editorial fashion and to the benefit of the trademark owner, with no intention of
infringement of the trademark.
Publisher: William Pollock
Project Editor: Karol Jurado
Assistant Editor: Nick Hoff
Editorial Production Assistant: Jennifer Arter
Cover and Interior Design: Octopod Studios
Composition: Magnolia Studio
Technical Editor: Nadav Savio
Copyeditor: Gail Nelson
Proofreader: Christine Sabooni
Indexer: Nancy Humphreys
Distributed to the book trade in the United States and Canada by Publishers Group
West, 1700 Fourth Street, Berkeley, California 94710, phone: 800-788-3123 or 510-528-
1444, fax: 510-528-3444
For information on translations or book distributors outside the United States, please
contact No Starch Press directly:
No Starch Press
555 De Haro Street, Suite 250
San Francisco, CA 94107
phone: 415-863-9900; fax: 415-863-9950;
info@nostarch.com
;
www.nostarch.com
The information in this book is distributed on an “As Is” basis, without warranty. While
every precaution has been taken in the preparation of this work, neither the author nor
No Starch Press shall have any liability to any person or entity with respect to any loss or
damage caused or alleged to be caused directly or indirectly by the information
contained in it.
Library of Congress Cataloging-in-Publication Data
Thau, Dave.
The book of JavaScript / Dave Thau.
p. cm.
Includes index.
ISBN 1-886411-36-0
1. JavaScript (Computer program language) I. Title.
QA76.73.J39 T37 2000
005.2'762--dc2 98-087609
Dedication
I dedicate this, my first book, to the first people in my life.
Thanks, mom and dad, for tricking me into becoming an engineer.
And for everything else as well.
Acknowledgments
This book was truly a collaborative effort. Thanks to Nick Hoff for patiently editing my
addled prose and giving me the various swift kicks I needed to finish this thing, William
Pollock for talking me into writing this book and helping shape its overall direction, Nadav
Savio for making sure my scripts actually worked, Karol Jurado and Gail Nelson for
dotting my i’s and crossing my t’s, and Amanda Staab for getting the word out. And a big
thanks to my sweetheart Kirsten, for tolerating the many missed weekends and the
evening hours filled with the clamoring of this keyboard.
Praise for
The Book of Javascript
“Real-world scripts that you can plug into your pages . . . [and] a patient tutor’s
explanation of how they work.”
—Jim Heid, Conference Chair, Thunder Lizard’s “Web Design” conferences
“Thau’s JavaScript tutorials at Webmonkey.com are so insanely popular, they’ve earned
him a Plato-like following of devoted fans. . . .Thanks to this book/CD-ROM combo . . .
Thau-mania is destined to grow to Elvis proportions.”
—Evany Thomas, Managing Editor of Webmonkey.com
“…an approachable introduction to contemporary JavaScript scripting practices. Its clear
and concise examples make an intimidating subject seem quite friendly.”
—Michael Masumoto, Multimedia Studies Program Instructor at San Francisco State
University
Foreword
I learned JavaScript completely on my own. There was no one to tell me about “event
handlers” or how to set cookies. No one even explained what a variable is, let alone the
best ways to name them. Of course I had reference books, but they were intimidating
tomes, full of cryptic lists and tables, written by programmers for programmers.
David Thau is a remarkable combination of natural teacher and seasoned programmer.
As a result,
The Book of JavaScript
not only teaches JavaScript thoroughly and
enjoyably in a friendly, unintimidating tone, but it teaches programming as elegantly as
any book I’ve seen. In fact, I’ve always thought of this as Thau’s ulterior motive—he
pretends he’s just showing you how to make a rollover or validate the text in an HTML
form, but before you know it you’ve learned how to code!
Perhaps the most telling thing I can say is that, reading this book, I can’t help but wish I
was learning JavaScript for the first time. If you are, then consider yourself lucky to have
Thau as a teacher. You couldn’t do better.
Happy JavaScripting!
Nadav Savio
Preface
You are about to begin a journey through JavaScript—a programming language that
adds interactivity and spark to Web pages all over the Internet. This book, written
primarily for nonprogrammers, provides scripts you can cut and paste into your Web site,
but it also makes sure you understand how they work so you can write your
own
scripts.
Each chapter in the book focuses on a few important JavaScript features, shows you
how professional Web sites incorporate them, and takes you through examples of how
you might add those features to your own Web pages.
Before you dive in, here is a quick overview of what you’ll learn as you make your way
through
The Book of JavaScript
.
Chapter 1
lays out the book’s goals, describes JavaScript and compares it with other
tools, explains some of the nifty ways in which JavaScript can enhance your Web pages,
and takes you through writing your first JavaScript.
Chapter 2
describes how JavaScript figures out what day it is and writes that date to a
Web page. Along the way you’ll learn how JavaScript remembers things using variables
and performs actions using functions.
Chapter 3
shows you how to direct someone to a Web page specifically designed for his
or her browser. This involves figuring out what browser the visitor is using, then making a
decision based on that information using if-then statements and their kin.
Chapter 4
covers that favorite JavaScript trick—an image swap. You’ll also learn how to
trigger JavaScript based on a viewer’s actions.
Chapter 5
tells you everything you need to know about opening new browser windows—
the second-favorite JavaScript trick. You’ll also learn how JavaScript writes HTML to the
new windows, closes them, and moves them around on screen.
Chapter 6
explains the magic of writing your own JavaScript functions. Functions are the
major building blocks of any JavaScript program, so learning to write your own is a
critical step to JavaScript mastery.
Chapter 7
shows you how JavaScript works with HTML forms to collect all kinds of
information from your users and give them fancy ways to navigate your site.
Chapter 8
describes how JavaScript deals with lists, whether they’re of all the images on
a Web page or of all the friends in your address book. JavaScript calls lists
arrays,
and
they come in very handy.
Chapter 9
discusses setting events to occur at specific times. For example, you can
open a window and then close it in 5 seconds, or you can write a clock that updates
every second. Once you know how to do this, you can create games and other
interactive applications based on timed events.
Chapter 10
discusses how JavaScript works with HTML frames. It covers topics
including changing two or more frames at once and preventing your Web pages from
getting trapped in someone else’s frame set.
Chapter 11
shows how to make sure people are filling out your HTML forms correctly.
Along the way, you’ll learn fancy ways to check user input—for example, you can check
the formatting of an email address.
Chapter 12
covers cookies. These bits of code let your Web pages save information a
visitor has provided even after he or she turns off the computer. This allows your site to
greet guests by name whenever they visit (if they tell you their name, of course!).
Chapter 13
introduces Dynamic HTML, a feature of newer browsers that lets you
animate entire Web pages.
Chapter 14
wraps things up by giving you tips on what to do when the JavaScript you’ve
written isn’t working correctly.
Appendix A
covers how JavaScript can interact with other programs your browser may
include—Java, ActiveX, and QuickTime, for example.
Appendix B
offers answers to the assignments that end each chapter.
Appendix C
provides a complete list of all the objects and functions that comprise
JavaScript.
Have fun!
Chapter 1:
Welcome to JavaScript!
Welcome to
The Book of JavaScript
. JavaScript is one of the fastest and easiest ways to
make your Web site truly dynamic. If you want to spruce up tired-looking pages, you’ve
got the right book.
This book will give you ready-made JavaScripts you can implement immediately on your
Web site, and I’ll take you step by step through sample scripts (both hypothetical and
real-world examples) so you
understand
how JavaScript works. With this understanding,
you can modify scripts to fit your specific needs as well as write scripts from scratch.
Your knowledge of JavaScript will grow as you work through the book; each chapter
introduces and explores in depth a new JavaScript topic by highlighting a real-life Web
site that uses it.
Is JavaScript for You?
If you want a quick, easy way to add interactivity to your Web site, if the thought of using
complex programs intimidates you, or if you’re simply interested in programming but
don’t know where to start, JavaScript is for you.
JavaScript, a programming language built into your Web browser, is one of the best
ways to add interactivity to your Web site because it’s the only cross-browser language
that works directly with Web browsers. Other languages, such as Java, Perl, and C, don’t
have direct access to the images, forms, and windows that make up a Web page.
JavaScript is also very easy to learn. You don’t need any special hardware or software,
you don’t need access to a Web server, and you don’t need a degree in computer
science to get things working. All you need is a Web browser and a text editor such as
SimpleText or Notepad.
Finally, JavaScript is a
complete
programming language, so if you want to learn more
about programming, it provides a great introduction. If you don’t give a hoot about
programming, that’s fine too. There are plenty of places—including this book and its
bundled CD-ROM—where you can get prefab scripts to cut and paste right into your
pages.
Is This Book for You?
This book assumes you don’t have any programming background. Even if you have
programmed before, you’ll find enough that’s new in JavaScript to keep you entertained.
One of the best things about JavaScript is that you don’t have to be mega-geeky to get it
working on your Web pages right away. You
do
need a working knowledge of HTML,
however.
The Goals of This Book
The main goal of this book is to get you to the point of writing your own JavaScripts.
Equally important, however, is the ability to read other people’s scripts. JavaScript is a
sprawling language, and you can learn thousands of little tricks from other scripts. In fact,
once you’ve finished this book, you’ll find viewing the source code of JavaScript Web
pages the best way to increase your knowledge.
Each of the following chapters includes JavaScript examples from professional sites.
You’ll soon see there are many ways to script, and sometimes going through the site’s
code unearths interesting corners of JavaScript that I don’t cover in this book.
Beyond learning how to write your own JavaScript and read other people’s scripts, I also
want you to learn where to look for additional information on JavaScript. The best place
to learn new techniques is to view the source of a Web page you find interesting. Several
Web sites also offer free JavaScripts. I’ll be introducing some of these as we go along,
but here are a few good examples to get you started:
http://www.js-planet.com
http://www.developer.earthweb.com/directories/pages/dir.javascript.html
http://www.javascript.com
Another good place to get information is a JavaScript reference book.
The Book of
JavaScript
is primarily a tutorial for learning basic JavaScript and making your Web site
interactive. It’s not a complete guide to the language, which includes too many details for
even a 400-page introduction to cover. If you’re planning to become a true JavaScript
master, I suggest picking up
JavaScript: The Definitive Guide
by David Flanagan
(O’Reilly and Associates, 1998) after making your way through this book. The last 500 or
so pages of Flanagan’s book not only list every JavaScript command, but also tell you in
which browsers they work.
What Can JavaScript Do?
JavaScript can add interactivity to your Web pages in a number of ways. This book offers
many examples of JavaScript’s broad capabilities. The following are just two examples
that illustrate what you can do with JavaScript.
The first example (
Figure 1-1
) is a flashing grid of colored squares (to get the full effect,
visit
http://hotwired.lycos.com/webmonkey/demo/96/35/index4a.html
or the bundled CD-
ROM under chapter01/fig1-1.html) created by a fellow named Taylor. Flashy, isn’t it? In
[ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • odszkodowanie.xlx.pl
  • Linki

    Strona Główna
    Nowicki Andrzej- Ateizm, e-book, Filozofia, Nowicki andrzej
    Nowy Sącz Stary Sącz Gorllice Limanowa Krynica Zdrój Rabka Zdrój 117 500 e-book, Turystyka, mapy, atlasy
    Nova Gramatica da Lingua Portuguesa para concursos - Rodrigo Bezerra - .2015, - Biblioteca - Biblioteka - Library, - EBOOKs PORTUGUÊS
    Nietzsche Fryderyk - Zmierzch Bozyszcz(1), Czysta filozofia, E-BOOK FILOZOFIA
    Nlp Book 3 Milton H Erickson - Experiencing Hypnosis, EBOOKI PDF, NLP
    Nowa matura Język angielski + 2 płyty CD Poziom podstawowy i rozszerzony Grzegorczyk Marzena E-BOOK, Podręczniki, lektury
    Novo Código de Processo Civil para concursos 2016---, - Biblioteca - Biblioteka - Library, - EBOOKs PORTUGUÊS
    Novidades! Súmula 575 do STJ (art 310 CTB), - Biblioteca - Biblioteka - Library, - EBOOKs PORTUGUÊS
    Noir Anxiety (by Kelly Oliver & Benigno Trigo) (2003), Ebooks (various), Noir
    Nowa Przygoda z nauczaniem-uczeniem się 3 Scenariusze lekcji część 1 Jas Małgorzata E-BOOK, Podręczniki, lektury
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • darkenrahl.keep.pl