Body onloadEvent
Body Object
Definition and Usage
The onload event triggers immediately after the page has finished loading.
Syntax
onload="JavaScriptCode"
| Parameters | Description |
|---|---|
| JavaScriptCode | Required. Specifies the JavaScript to execute when the event occurs. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the onload event
Examples
Examples
In this example, the text "Page is loaded" will be displayed in the status bar:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
<script>
function myFunction(){
alert("Page loaded");
}
</script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
<script>
function myFunction(){
alert("Page loaded");
}
</script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
</body>
</html>
Try it Yourself »
Body Object Other Extensions