onload Event

DHTML, HTML, & CSS

 
Click to return to the DHTML, HTML & CSS home page    
onkeyup Event     onlosecapture Event     DHTML Events    

onload Event


Fires immediately after the browser loads the object.

Syntax

Inline HTML<ELEMENT onload = "handler" ... >All platforms
Event propertyobject.onload = handlerJScript (compatible with ECMA 262 language specification) only
Named script<SCRIPT FOR = object EVENT = onload>Internet Explorer only

Remarks

BubblesNo
CancelsNo
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.

Event Object Properties

clientXRetrieves the x-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars.
clientYRetrieves the y-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars.
offsetXRetrieves the horizontal coordinate of the mouse's position relative to the object firing the event.
offsetYRetrieves the vertical coordinate of the mouse's position relative to the object firing the event.
screenXRetrieves the horizontal position of the mouse, in pixels, relative to the user's screen.
screenYRetrieves the vertical position of the mouse, in pixels, relative to the user's screen.
typeRetrieves the event name from the event object.
xRetrieves the x-coordinate of the mouse cursor relative to the parent element.
yRetrieves the y-coordinate of the mouse cursor relative to the parent element.

Example

Sample Code

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

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
APPLET, EMBED, FRAMESET, IMG, LINK, SCRIPT, window

See Also

onreadystatechange, onunload


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.