JavaScript onload Event

The onload event in JavaScript triggers when a web page loads in a browser.

Note - The onload Event is defined in BODY element.

JavaScript onload Event Example

Here is an example demonstrates onload event in JavaScript:

<!DOCTYPE HTML>
<html>
<head>
   <title>JavaScript onload Event</title>
</head>
<body onload="alert('Welcome to JavaScript from fresherearth.com!')">

<h3>JavaScript onload Event Example</h3>
<p>You will see an alert box showing an alert message on body load.</p>

</body>
</html>

Here is the sample output of the above JavaScript onload event example:

javascript onload event

JavaScript Online Test


« Previous Tutorial Next Tutorial »