How to deliver a random page from a single link?
June 27, 2007 10:35 AM   Subscribe

If I have "page1.html", 'page2.html", "page3.html" and "page4.html" and on examplehomepage.com I have a link that says, "give me a random page" how do I make it so that link delivers 1,2,3 or 4 randomly each time the link is clicked?

I am building my first website, using Nvu. I think I get the basic concepts. I know this random page thing is probably way over my head as I am such a novice, but I really want to include it. I am hoping it is easy enough that askmefi can save me once again!
posted by wtfwjd? to Computers & Internet (2 answers total) 4 users marked this as a favorite
 
The easiest way to do this is with Javascript. You'll put the different pages name into an array and when you click on the link, call a Javascript method that sends you to a random page in the array.
posted by turaho at 10:46 AM on June 27, 2007


<a href="#" onclick="setTimeout(function() { window.location.href = 'page' + Math.floor((Math.random() * 4 + 1)) + '.html' }, 1); return false">give me a random page</a>
posted by Khalad at 10:46 AM on June 27, 2007


« Older Halp!   |   Detroit after 5:00 p.m. Newer »
This thread is closed to new comments.