| Chapter 13: The Nuts and Bolts of JavaScript |
|
|
|
| Sections - Part IV: Integrating Scripts with (X)HTML | |||
|
A lot of good "canned JavaScript" is available for free on the Web; you know what we mean -- scripts written by someone else that you simply copy and paste into your HTML page. But as good as canned scripts can be, copy-and-paste goes only so far. Sooner or later, you're going to encounter unique needs that can't be fulfilled with a free script. Canned JavaScript is much like canned Spam (the meat product, not the e-mail affliction): Great for convenience, but you probably don't want to make it an exclusive diet. Instead, knowing how to script -- or at least how to tweak a prewritten script -- is as important as knowing how to fix some good ol' fashioned home cooking. In this chapter, you "open the can" of the JavaScript language and have a look at what's inside. (Don't worry; you won't encounter any meaty pink substances along the way.) You discover how to plug scripts into your pages, how to bundle your scripts into external JavaScript files to save time and effort, and how the nuts and bolts of the JavaScript language work. Finally, at the end of this chapter, we point you to good sources of additional information about JavaScript. These will come in handy as your scripting needs advance. Page 224, Listing 13-1: Header script (display view) (code view) Note that you may need to load the display view once to get it to work properly. On at least one of our test machines, it worked this way (load once, then try again, and everything works fine) Page 226, Listing 13-2: External script reference (display view) (code view) Page 227, Listing 13-3: An external JavaScript file (display view) (code view) Page 236, Figure 13-1: Confirming an action (display view) (code view) Page 237, Listing 13-4 and Figure 13-2: A "for" loop (display view) (code view) Page 238, Listing 13-5: A while loop (display view) (code view) Page 240, Listing 13-6, Figure 13-3: Calling a function (display view) (code view)
.ZIP file of all code samples from this chapter (10kb)
|
|||
| Last Updated on Monday, 30 June 2008 11:41 |