Donate SIGN UP

Random URL

Avatar Image
MTIH1992 | 01:27 Fri 15th Sep 2006 | Technology
4 Answers
Hello AB users. I am on the hunt looking for a specific Javascript.
I need one that i can put on my website that automaticaly forward after a specified amount of time (that i will specify) to a URL in a list of many URL's that i will put into a javascript.
I need the javascript to randomly select one of the URL's and forward the page automaticaly to that specified URL.

For example:

< script/ >
bla bla bla
forward to random URL after X seconds:
[1]=http://www.google.com
[2]=http://www.info.com
[3]=http://www.yahoo.com
< script/ >

and the script would select one of the three URL's i gave it to forward to after the amount of seconds i specify as X.

Please help as this is absalutly vital for me. Thanks, Matt
Gravatar

Answers

1 to 4 of 4rss feed

Best Answer

No best answer has yet been selected by MTIH1992. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
Just wrote this now (some of it grabbed from some public domain script),

rnd.today = new Date();
rnd.seed = rnd.today.getTime();
function rnd() {
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);};
var link = new Array("","http://www.google.com","http://www.theanswerba nk.co.uk");
var randseed = Math.ceil(rnd()*(link.length-1));
setTimeout("document.location = link[randseed]",3000);
If you copy and paste it from this page it should work fine. Just enclose it in some script tags, obviously.

It's currently set to change page after 3 seconds (3000 milliseconds), and I've set two choices of page. To add any more pages just add a comma to the end like it shows, and type another address in double quotes.
Question Author
Wow! Thanks! :D
Question Author
what script tags?

1 to 4 of 4rss feed

Do you know the answer?

Random URL

Answer Question >>