2.2  HTML2 - Creating a Menu with JavaScript

Index Code Tester

OBJECTIVE

DISCUSSION

Example Client Page (Client page = page that has the menu on it) 

<html>
<head>
<script src = "myScript.js"></script>
</head>
<body>
<table width="100%" height = "100%">
<tr valign = "top">
<td width = "150px" bgcolor="yellow">Contents<br>
<script>writeMenu("")</script>
</td>
<td>Main stuff here
</td>
</tr>
</table>
</body>
</html>
    

Example Code in JavaScript File

   
function writeMenu(pathToJS) {
	document.write("<a href = '" + pathToJS + "http://cnn.com'>cnn</a><br>");
}

   

EXERCISES

  1. Create a "client page" by copying and pasting the above code into a new page. 
  2. Create the JavaScript page by copying and pasting the above code into a file named myScript.js.
  3. Test your page.
  4. Add a link to another page that is in the same directory as your "client page".
  5. Add a link to a page in another directory. 
  6. Add the menu to the page in the other directory. 

LINKS AND HELP

Frames: http://www.w3schools.com/html/html_frames.asp