English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The load event is triggered when a resource and its dependent resources have completed loading.
Execute JavaScript immediately after page load:
<!DOCTYPE html> <html> <head> <title>HTML onload event attribute usage (Basic Tutorial Website oldtoolbag.com)</title> <script> function myFunction() { alert("Page is loaded"); } </script> </head> <body onload="myFunction()"> <h1>Hello World!</h1> </body> </html>Test and see ‹/›
IEFirefoxOperaChromeSafari
All major browsers support the onload event attribute.
The onload attribute is triggered after the loading of an object.
Once the webpage has completely loaded all content (including images, script files, CSS files, etc.), onload is typically used within the <body> element to execute scripts. However, it can also be used on other elements (see the 'Supported HTML Tags' below).
The onload attribute can be used to check the visitor's browser type and version, and load the correct version of the webpage based on this information.
The onload attribute can also be used to handle cookies.
No difference.
<element onload="script">
Value | Description |
---|---|
script | Specifies the script to be executed when the onload event is triggered. |