Random browser redirection

In this project JavaScript loads a randomly selected from a list location to the browser. The actual loading is disabled to allow you to examine the source code of this document. To enable the redirection you will need to uncomment the marked code line in the function redirect().

The URLs used for the redirection are stored in array URLs defined in the document header. In is important to put this code to the header in order it would be processed before composing the document body.

<html>
<head>
<script type="text/javascript">
var URLs = new Array();               // array of web URLs
URLs[0] = "http://www.yahoo.com";
URLs[1] = "http://www.uwsuper.edu";
URLs[2] = "http://www.google.com";
URLs[3] = "http://www.mozilla.com";
URLs[4] = "http://java.sun.com";
URLs[5] = "http://cs.uwsuper.edu";

The actual redirection is done by the function redirect() defined in the header of the document:

function redirect()                   // this function will be called every
{                                     // time this page is loaded
  // compute random array index
  var randomIndex = Math.floor(Math.random() * URLs.length);

  // redirect the browser by choosing URL with the index computed above
  // UNCOMMENT THE NEXT LINE TO ALLOW THE REDIRECTION
//  window.location = URLs[randomIndex];
}
</script>
</head>

The function redirect() will be called by using the onload event handler, which is defined within the document body tag:

<body onload="redirect()">

</body>
</html>

In this case the document body is empty because it will be substituted with the one of the redirected document.