Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
load EventIn several earlier examples, we used the window object’s load event to begin executing scripts. This event fires when the window finishes loading successfully (i.e., all its children are loaded and all external files referenced by the page are loaded). Actually, every DOM element has a load event, but it’s most commonly used on the window object. The example of Figs. 13.1–13.2 reviews the load event. The load event’s handler creates an interval timer that updates a span with the number of seconds that have elapsed since the document was loaded. The document’s (Fig. 13.1) paragraph contains the span (line 14).
 1   <!DOCTYPE html>
 2
 3   <!-- Fig. 13.1: onload.html -->
 4   <!-- Demonstrating the load event. -->
 5   <html>
 6      <head>
 7         <meta charset = "utf-8">
 8         <title>load Event</title>
 9         <link rel = "stylesheet" type = "text/css" href = "style.css">
10Â Â Â Â Â Â Â Â Â <script src = "load.js"></script>
11Â Â Â Â Â Â </head>
12Â Â Â Â Â Â <body>
13Â Â Â Â Â Â Â Â Â <p>Seconds you have spent viewing this page so far:
14Â Â Â Â Â Â Â Â Â <span id = "soFar">0</span></p>
15Â Â Â Â Â Â </body>
16Â Â Â </html>