Call your function in body onLoad event in JavaScript

Description

The following code shows how to call your function in body onLoad event.

Example


<!--from  www. java  2s .c  o m-->
<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
function yourMessage()
{
document.writeln("Your first function!");
}
</script>
</head>
<body onLoad="yourMessage()">
</body>
</html>

Click to view the demo

The code above generates the following result.

Call your function in body onLoad event in JavaScript