HTML onload event attribute
Example
Execute a JavaScript immediately after the page is loaded:
<body onload="load()">
Browser support
IE | Firefox | Chrome | Safari | Opera |
---|---|---|---|---|
All mainstream browsers support the onload attribute.
Definition and usage
The onload attribute is triggered when the object is loaded.
onload is commonly used in <body>, and a script is executed once all content (including images, script files, CSS files, etc.) is fully loaded.
Differences between HTML 4.01 and HTML5
None.
Syntax
<element onload="script">
Attribute value
Value | Description |
---|---|
script | Script executed when onload occurs. |