This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
This program is an example only. Computing your actual income tax is almost always more complicated than this!
<MAP NAME="map1"> In Example 12.3 note that the onMouseOver() event handler must return true. This tells the browser that it should not perform its own default action for the event--that is, it should not display the URL of the link in the status line. If you forget to return true, then the browser will overwrite whatever message the handler displayed in the status line with its own URL. When you move the mouse pointer over a hyperlink, the browser displays the URL for the link, and then erases it when the mouse moves off the hyperlink. The same is true when you use an onMouseOver() event handler to setor
You have visited ' + visitordata.visits + ' times.');
<SCRIPT> // Create a bunch of off-screen images, and get them started // loading the images we're going to animate. images = new Array(10); for(var i = 0; i < 10; i++) { images[i] = new Image(); // Create an Image object images[i].src = "images/" + i + ".gif"; // tell it what URL to load } // Later, when we want to perform our animation, we can use these URLs, // knowing that they've been loaded into the cache. Note that we perform // the animation by assigning the URL, not the Image object itself. // Also note that we call the image by name, rather than as document.images[0]. function animate() { document.animation.src = images[frame].src; frame = (frame + 1)%10; timeout_id = setTimeout("animate()", 250); // display next frame later } var frame = 0; // Keep track of what frame of the animation we're on. var timeout_id = null; // This allows us to stop the animation. Example 16.1 demonstrates the important steps involved in creating an off-screen image for image caching. The first
<SCRIPT> // Count how many images have been loaded. When we reach 10, start animating. function count_images() { if (++num_loaded_images == 10) animate(); } var num_loaded_images = 0; // Create the off-screen images and assign the image URLs. // Also assign an event handler so we can count how many images have been // loaded. Note that we assign the handler before the URL, because otherwise // the image might finish loading (e.g., if it is already cached) before // we assign the handler, and then we'll lose count of how many have loaded! images = new Array(10); for(var i = 0; i < 10; i++) { images[i] = new Image(); // Create an Image object images[i].onload = count_images; // assign the event handler images[i].src = "images/" + i + ".gif"; // tell it what URL to load } function animate() // The function that does the animation. { document.animation.src = images[frame].src; frame = (frame + 1)%10; timeout_id = setTimeout("animate()", 250); // display next frame later } var frame = 0; // Keep track of what frame of the animation we're on. var timeout_id = null; // This allows us to stop the animation. In addition to the onLoad() event handler, the Image object also supports two others. The onError() event handler is invoked when an error occurs during image loading, such as when the specified URL refers to a corrupt image data. The onAbort() handler is invoked if the user aborts the image load (for example, by clicking the Stop button in the browser) before it has finished. For any image, one (and only one) of these handlers will be called. In addition to these handlers, each Image object also has a complete property. This property is false while the image is loading, and is true once the image has loaded or once the browser has stopped trying to load it. That is, the complete property becomes true once one of the three possible event handlers is invoked.