JavaScript functions can be automatically invoked without an event.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvUWwju6SiHG7MM6aDO1RlmKSxnAI8-0hdolBtx1gIczCvjYEu60spq0rwjciyP4Bv3uyWXBHNhJdUR7Ffm3VIxENW1feYyHi1zZlmT0audvscxHq9nS7s1cARaeGtCWZidjuQfg/s1600/Call+a+JavaScript+function+inside+body+of+a+web+page+www.digizol.com.png)
<body onLoad="javascript:myfunction()" >
Yes, and it's easy. Just call the function inside your page as same as you would write JavaScript inside the body of a page.
<script type="text/javascript" language="JavaScript">
doSomething('params');
</script>
In this example, doSomething() function is added to the web page inside the header of the page. And for ease of understanding the complete code is shown below.
<html>
<head>
<script type="text/javascript" language="JavaScript">
function doSomething(params);
//do something nice with params
}
</script>
</head>
<body>
This page does call a JavaScript function when the page is loaded,
without using the onload() event call.
<script type="text/javascript" language="JavaScript">
doSomething('blue');
</script>
</body>
</html>
COMMENTS