Archive for 12th September 2007

A Simple Random Link JavaScript

Recently asked on Yahoo! Answers:

How do I make a link that takes the user to a random page?

I’ve seen a lot of sites that takes the user to a random page, like Wikipedia, or any site that does it, but I look at the link in the taskbar and it says something like www.example.com/example.html#, does the # have significance in something? Then how do I make a link that takes the user to a list of certain sites I have?

This is easily done in any Web programming language:

  1. Create an array of URLs you want to use as “random” elements.
  2. Generate a random number between 0 and one less than the length of the array.
  3. Select that array cell and echo it out as the href attribute of a link element.

For this demo, I will use JavaScript, since it doesn’t involve a server technology.

Continue reading ‘A Simple Random Link JavaScript’ »