next up previous
Next: More Functions Up: First Steps in JavaScript Previous: A Simple Example 1

A Simple Example 1 -- Hello World with a function

You may freely write JavaScript in any place in your Web page.

However if you wish to trigger actions from certain events you may wish to put your JavaScript in functions in the Head section of the document.

The Hello World program called from a function is as follows:

<html>
 <head>
   <script language="javascript">

   function init(){
   
   var str = "Hello World";

   window.alert(str);
 
   document.write("<h1>" + str + "</h1>");
 
   }
  
   </script>
 </head>

<body onLoad="init()">

</body>
</html>

The operation of the program is essentially the same except that



Dave Marshall
9/28/2001