English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Referenzhandbuch

Vollständiges Verzeichnis der HTML-Tags

HTML onload-Eigenschaft

Wenn eine Ressource und ihre abhängigen Ressourcen vollständig geladen sind, wird das load-Ereignis ausgelöst.

HTML Event Attributes

Online-Beispiel

JavaScript wird sofort nach dem Laden der Seite ausgeführt:

<!DOCTYPE html>
<html>
<head>
<title>Verwendung der onload-Eigenschaft von HTML (Grund教程网 oldtoolbag.com)</title>
<script>
function myFunction() {
  alert("Seite wurde geladen");
}
</script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
</body>
</html>
Test see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the onload event attribute.

Definition and Usage

The onload attribute is triggered after the object is loaded.
Once the web page has completely loaded all content (including images, script files, CSS files, etc.), onload is typically used within the <body> element to execute scripts. However, it can also be used on other elements (see the following 'Supported HTML Tags').
The onload attribute can be used to check the visitor's browser type and version, and load the correct version of the web page based on this information.
The onload attribute can also be used to handle cookies.

HTML 4.01 and HTML5Differences between

No differences.

Syntax

<element onload="script">

Attribute Value

ValueDescription
scriptSpecifies the script to be executed when the onload event is triggered.
HTML Event Attributes