Previous Page
Next Page

Introduction

Welcome to JavaScript! Using this easy-to-learn programming language, you'll be able to add pizzazz to your Web pages and make them more useful for you and for your site's visitors. We've written this book as a painless introduction to JavaScript, so you don't have to be a geek or a nerd to write a script. Pocket protectors will not be necessary at any time. As a friend of ours says, "We're geeky, so you don't have to be!"

We Wrote this Book for You

We figure that if you're interested in JavaScript, then you've already got some experience in creating HTML pages and Web sites, and you want to take the next step by adding some interactivity to your sites. We don't assume that you know anything about programming or scripting. We also don't assume that you are an HTML expert (though if you are, that's just fine). We do assume that you've got at least the basics of building Web pages down, and that you have some familiarity with common HTML, such as links, images, and forms.

We include some extra explanation of HTML in sidebars called "Just Enough HTML." You won't find these sidebars in every chapter, just the ones where we think you'll need a quick reference. Having this HTML information handy means you won't need two books open just to remember the syntax of a particular HTML attribute. We also think that you should have at least a nodding familiarity with CSS (Cascading Style Sheets), but we've included just about all the information you might need to get going if you haven't worked with CSS before.

If you already know something about programming, you should be aware that we don't take the same approach to JavaScript as you might have seen in other books. We don't delve deeply into JavaScript's syntax and structure, and we don't pretend that this book is a comprehensive language reference (though you'll find some valuable reference material in Appendix A, the color section in the back of the book). There are several other books on the market that do that job admirably, and we list them at the end of this book, in Appendix D. The difference between those books and this one is that instead of getting bogged down in formalism, we concentrate on showing you how to get useful tasks done with JavaScript without a lot of extraneous information.

New in this edition, we've added an introduction to Ajax, a technique that uses JavaScript and other common Web technologies to add extra interactivity to Web pages, and to improve the user experience of your Web sites. We give you Ajax basics and then add practical examples that will allow you to Ajax-ify your sites without getting an advanced degree in Web programming.

How to Use this Book

Throughout the book, we've used some devices that should make it easier for you to work with both the book and with JavaScript itself.

In the step-by-step instructions that make up most of the book, we've used a special type style to denote either HTML or JavaScript code, like this:

<div align="center">
window.onload = initLinks;

You'll also notice that we show the HTML and the JavaScript in lowercase. We've done that because all of the scripts in this edition are compliant with the XHTML 1.0 Transitional standard from the W3C, the World Wide Web Consortium. Whenever you see a quote mark in a JavaScript, it is always a straight quote (like ' or "), never curly quotes (aka "smart" quotes, like ' or "). Curly quotes will prevent your JavaScript from working, so make sure that you avoid them when you write scripts.

In the illustrations accompanying the step-by-step instructions, we've highlighted the part of the scripts that we're discussing in red, so you can quickly find what we're talking about. We often also highlight parts of the screen shots of Web browser windows in red, to indicate the most important part of the picture.

Because book pages are narrower than computer screens, some of the lines of JavaScript code are too long to fit on the page. When this happens, we've broken the line of code up into one or more segments, inserted this gray arrow to indicate that it's a continued line, and indented the rest of the line. Here's an example of how we show long lines in scripts.

dtString = "Hey, just what are you doing up so late?";

You Say Browser, We Say Kumbaya

We've made a big change in this edition; we have ended our support for browsers that are very old or that don't do a good job of supporting Web standards. Since our last edition, virtually all Web users have upgraded and are enjoying the benefits of modern browsers, ones that do a good-to-excellent job of supporting commonly accepted Web standards like XHTML, CSS2, and the Document Object Model. That covers Internet Explorer 6 or later; Firefox 1.0 or later; Netscape 7 or later; all versions of Safari; and Opera 7 or later.

If you do need to support older browsers, you'll need to use some older techniques. We covered those browser-specific techniques in previous editions, but we decided to make a clean break from the old ways of doing things this time around and took that information out of the printed book. We didn't want to lose that content entirely, so we are making it available as Chapter 18, "Working with Older Browsers," in the form of a downloadable PDF on the book's companion Web site. Just go to www.javascriptworld.com, click the Resources link, and you'll find the Chapter 18 file waiting for you. While you're there at the Web site, take a look around; chances are you'll find lots of other interesting things.

We (along with our crack team of testers) have tested our scripts in a wide variety of browsers, on several different operating systems, including Windows XP, Mac OS X, and Ubuntu Linux. Windows Vista had not arrived in final form as we went to press, and the public beta versions were still too subject to change, so we passed on using Vista for this edition.

We used the 600-pound gorilla of the browser world, Microsoft Internet Explorer 6 for Windows, to test virtually everything in the book, and did extensive testing with public beta versions of IE 7 (we went to press before the final version of IE 7 was released). We also tested the scripts with Firefox 1.5 for Windows, Mac, and Linux. We didn't leave out the Mac users, of course; all of the scripts were tested in Safari 2. That means that they should also work in other browsers derived from the WebKit engine that drives Safari (such as the Omni Group's OmniWeb), and on browsers based on the open-source KHTML rendering engine from which Safari got its start (such as Konqueror for Linux).

Don't Type that Code!

Some JavaScript books print the scripts, and expect you to type in the examples. We think that's way too retro for this day and age. It was tough enough for us to do all that typing, and there's no reason you should have to repeat that work. So we've prepared a companion Web site for this book, one that includes all of the scripts in the book, ready for you to just copy and paste into your own Web pages. The site also includes additional tips and scripts. If we discover any mistakes in the book that got through the editing process, we'll list the updates on the site, too. You can find our companion site at:

http://www.javascriptworld.com/

If for some reason you do plan to type in some script examples, you might find that the examples don't seem to work, because you don't have the supporting files that we used to create the examples. For example, in a task where an on-screen effect happens to an image, you'll need image files. No problem. We've put all of those files up on the book's Web site, nicely packaged for you to download. You'll find one downloadable file that contains all of the scripts, HTML files, and any media files we used. If you have any questions, please check the FAQ (Frequently Asked Questions) page on the companion Web site. It's clearly marked.

If you've read the FAQ, and your question isn't answered there, you can contact us via email at: js6@javascriptworld.com. We regret that because of the large volume of email that we get, we cannot, and will not, answer email about the book sent to our personal email addresses. We can only guarantee that messages sent to the js6@javascriptworld.com address will be answered.

Time to Get Started

One of the best things about JavaScript is that it's easy to start with a simple script that makes cool things happen on your Web page then add more complicated stuff as you need it. You don't have to learn a whole book's worth of information before you can start improving your Web pages. But by the time you're done with the book, you'll be adding advanced interactivity to your sites with Ajax.

Of course, every journey begins with the first step, and if you've read this far, your journey into JavaScript and Ajax has already begun. Thanks for joining us; please keep your hands and feet inside the moving vehicle. And please, no flash photography.


Previous Page
Next Page