Availability
JavaScript 1.0
Synopsis
<body onload="handler" ... ><frameset onload="handler" ... >
window.onload
Description
The onload property of a Window specifies an event
handler function that is invoked when a document or frameset is
completely loaded into its window or frame.
The
initial value of this property is a function that contains the
semicolon-separated JavaScript statements specified by the
onload attribute of the
<body> or
<frameset> tags.
When the onload event handler is invoked, you can
be certain that the document has fully loaded, and therefore that all
scripts within the document have executed, all functions within
scripts are defined, and all forms and other document elements have
been parsed and are available through the Document object.
Usage
If any of your document's event handlers depend on the document
being fully loaded, you should check that it is loaded before
executing those handlers. If the network connection were to stall out
after a button appeared in the document but before the parts of the
document that the button relied on were loaded, the user would get
unintended behavior or an error message after clicking the button.
One good way to verify that the document is loaded is to use the
onload handler to set a
variable -- loaded, for example -- to
true and to check the value of this variable
before doing anything that depends on the complete document being
loaded.
See Also
Window.onunload; Chapter 19; Event, EventListener,
and EventTarget in the DOM reference section
•
Table of Contents
•
Index
•
Reviews
•
Examples
•
Reader Reviews
•
Errata
JavaScript: The Definitive Guide, 4th Edition
By
David Flanagan
Publisher
: O'Reilly
Pub Date
: November 2001
ISBN
: 0-596-00048-0
Pages
: 936
Slots
: 1
This fourth edition of the definitive reference to
JavaScript, a scripting language that can be embedded
directly in web pages, covers the latest version of the
language, JavaScript 1.5, as supported by Netscape 6 and
Internet Explorer 6. The book also provides complete
coverage of the W3C DOM standard (Level 1 and Level 2),
while retaining material on the legacy Level 0 DOM for
backward compatibility.