Definition and Usage
The onload event occurs immediately after a page or an image is loaded.
Syntax
οnlοad="JavaScriptCode" |
Parameter | Description |
---|---|
JavaScriptCode | Required. Specifies a JavaScript to be executed when the event occurs |
Supported by the following HTML tags:
<body>, <img> |
Supported by the following JavaScript objects:
body, image |
Browser Support
The onload event is supported in all major browsers.
Examples
Example 1Alert "Page is loaded" immediately after a page is loaded:
Try it yourself » |
Example 2Alert "Image is loaded" immediately after an image is loaded:
Try it yourself » |