Body onloadEvent

Body 对象参考手册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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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>

Try it Yourself »


Body 对象参考手册Body Object Other Extensions