JavaScript Reference
Note that function is invoked as a method of the Window object, which means
that the th is keyword refers to the Window object when used inside the body of
function .
The setInterval() method returns a value that can later be used as an argum ent of
clearInterval() to cancel the repetition of the invocation of function .
setTimeout()
Syntax:
window.setTimeout(function , timeout , arg1, arg2 , ..., argN )
This method is like set Interval(), except that it schedules a function invocation
only once: function will be invoked after timeout m illiseconds.
The setTimeout() me thod returns a value that can later b e used as an argume nt of
clearTimeout() to cancel the pending invocation of function .
Events
You can also use all of the event-handler properties that are defined on Element on the
Window objec t. T hat is possible because most events bubble up the document tree all
the way to the Window object. Window also defines some event-hand le r properties of
its own (e.g. , the onstorage event-handler property) but they are out of the scope o f
this b ook.
onload
Syntax:
window.onload = handlerFunction ;
This is a n event handler for the load event on the Window object, which is on e of the
most important handlers. The load event fires after the document, and all the external
resources referred to from within the document have been fully loaded and are ready
to be manipulated. The specified handlerFunction function is where JavaScript
code normally begins its execution.
Take, for example , the following cod e:
window.onload = function() {
document.getElementById("status").innerHTML =
"Boarding completed.";
};
Suppose there is an HT ML element with ID of status in the c orresponding docu-
ment. After the documen t has loaded, you see the text “Boarding completed.” written
in it.
E.17. window (Cl ient-Side JavaScript) 43 1