Fires immediately after the browser loads the object.
Syntax
Inline HTML <ELEMENT onload = "handler" ... > All platforms Event property object.onload = handler JScript (compatible with ECMA 262 language specification) only Named script <SCRIPT FOR = object EVENT = onload> Internet Explorer only
Remarks
Bubbles No Cancels No To invoke Open a page in the browser to invoke this event for the document or any object within it. Default action Loads the object for which the event is specified. The browser loads applications, embedded objects, and images as soon as it encounters the APPLET, EMBED, and IMG objects during parsing. Consequently, the onload event for these objects occurs before the browser parses any subsequent objects. To ensure that an event handler receives the onload event for these objects, place the SCRIPT object that defines the event handler before the object and use the onload attribute in the object to set the handler.
The onload attribute of the BODY object sets an onload event handler for the window. This technique of calling the window onload event through the BODY object is overridden by any other means of invoking the window onload event, provided the handlers are in the same script language.
Event Object Properties
Although event handlers in the DHTML Object Model do not receive parameters directly, the handler can query the event object for data.
clientX Retrieves the x-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars. clientY Retrieves the y-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars. offsetX Retrieves the horizontal coordinate of the mouse's position relative to the object firing the event. offsetY Retrieves the vertical coordinate of the mouse's position relative to the object firing the event. screenX Retrieves the horizontal position of the mouse, in pixels, relative to the user's screen. screenY Retrieves the vertical position of the mouse, in pixels, relative to the user's screen. type Retrieves the event name from the event object. x Retrieves the x-coordinate of the mouse cursor relative to the parent element. y Retrieves the y-coordinate of the mouse cursor relative to the parent element.
Example
This example uses an onload event handler to display a message in the window's status bar when the page has finished loading.
<BODY> <SCRIPT FOR=window EVENT=onload LANGUAGE="JScript"> window.status = "Page is loaded!"; </SCRIPT> </BODY>This example sets an onload event handler for an IMG object. The handler uses the event object to retrieve the URL of the image.
<SCRIPT> function imageLoaded() { window.status = "Image " + event.srcElement.src + " is loaded"; } </SCRIPT> <BODY> <IMG SRC="sample.gif" onload="imageLoaded()"> </BODY>
Applies To
APPLET, EMBED, FRAMESET, IMG, LINK, SCRIPT, window
See Also