Learn html - html tutorial - Onload attribute in html - html examples - html programs
The onload attribute executes a script when an object has been loaded.
onload is most often used within the <body> element to execute a script once a web page has entirely loaded all content (including images, script files, CSS files, etc.).
For input elements, the onload attribute is only supported though <input type="image">
The onload attribute may be used to check the user's browser type and version, and load the proper version of the web page based on the information.
The onload attribute is a section of the Event Attributes.
Tryit<!DOCTYPE html><html><head><title>Wikitechy HTML onload attribute</title><script>
function onLoad()
{
alert("Wikitechy Page is loaded")
}
</script></head><body onload="onLoad()"><h2>Welcome to Wikitechy!</h2></body></html>
Code Explanation for onload Attribute in HTML:
function onLoad () is a JavaScript function which is used to create an alert box when onload attribute is executed.
The onload attribute executes when an associated element has been loaded.
Output for onload Attribute in HTML:
When the page has been loaded the alert box displayed on the browser.
After clicking the ok button, the page has been displayed with the text welcome to Wikitechy!.