![]() |
Definition and UsageThe onload attribute fires when an object has been loaded. onload is most often used within the <body> element to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.). However, it can be used on other elements as well (see "Supported HTML tags" below). For input elements, the onload attribute is only supported when <input type="image"> The onload attribute can be used to check the visitor's browser type and browser version, and load the proper version of the web page based on the information. Applies toThe onload attribute is part of the Event Attributes, and can be used on the following elements:
Browser SupportThe
|
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
alert("Page is loaded");
}
</script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<img src="https://horje.com/avatar.png" onload="loadImage()" width="100" height="132">
<script>
function loadImage() {
alert("Image is loaded");
}
</script>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<input type="image" onload="loadImage()" src="https://horje.com/uploads/category/2024-08-31-06-56-41-php_script.png" alt="Submit" width="48" height="48">
<script>
function loadImage() {
alert("Image is loaded");
}
</script>
</body>
</html>
html onload attribute |
Read Full: | HTML Attribute |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Attribute |
Uploaded: | 1 week ago |
Uploaded by: | Admin |
Views: | 83 |
Reffered: https://www.w3schools.com/tags/att_onload.asp