HTML | onload Event Attribute
This attribute works when an object has been loaded. This attribute mostly used within the <body> element to execute a script. It can be used with other elements as well. This attribute is used to check the visitor’s browser type and browser version, and load the proper version of the web page based on the information.
Syntax:
<element onload = "script">
Attribute Value: This attribute contains single value script and it runs when onload event triggered. This attribute is associated with many HTML elements.
Example 1:
<!DOCTYPE html> < html > < head > < title >onload event attribute</ title > < script > function Function() { alert("Page is loaded"); } </ script > < style > body { text-align:center; } h1 { color:green; } </ style > </ head > < body onload = "Function()" > < h1 >GeeksforGeeks</ h1 > < h2 >onload event attribute</ h2 > </ body > </ html > |
Output:
Example 2:
<!DOCTYPE html> < html > < head > < title >onload event attribute</ title > </ head > < body > < img src = onload = "loadImage()" width = "500" height = "132" > < script > function loadImage() { alert("Image loaded successfully"); } </ script > </ body > </ html > |
Output:
Supported Browsers: The browser supported by onload attribute are listed below:
- Chrome
- Internet Explorer
- Firefox
- Safari
- Opera
Recommended Posts:
- HTML | DOM onload Event
- HTML | oninvalid Event Attribute
- HTML | onunload Event Attribute
- HTML | onreset Event Attribute
- HTML | onsubmit Event Attribute
- HTML | onresize Event Attribute
- HTML | ondrop Event Attribute
- HTML | onwheel Event Attribute
- HTML | oncontextmenu Event Attribute
- HTML | ondrag Event Attribute
- HTML | onpaste Event Attribute
- HTML | onkeyup Event Attribute
- HTML | onkeydown Event Attribute
- HTML | onmouseover Event Attribute
- HTML | ondragover Event Attribute
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.