View Full Version : random redirect
angiras
01-25-2003, 11:40 AM
I would like to redirect and random the redirection from an array of links
anyone has a good example ?
thank you !
redhead
01-25-2003, 12:24 PM
take a look at some of these:
http://www.javascriptkit.com/script/cutindex15.shtml
angiras
01-25-2003, 12:28 PM
I think I shall find what I need :-)
thank you
angiras
01-25-2003, 12:48 PM
I got an error somewhere
<head>
<script type="text/javascript" language="javascript">
var randomlinks=new Array()
randomlinks[0]="http://freewarejava.com"
randomlinks[1]="http://javascriptkit.com"
randomlinks[2]="http://dynamicdrive.com"
randomlinks[3]="http://cnn.com"
randomlinks[4]="http://www.geocities.com"
parent.location.href = randomlinks[Math.floor(Math.random()*randomlinks.length)]} setTimeout('redirect()', 0)
</script>
</head>
if anyone know what is wrong !
thank you !
i haven't tried you code but why do you use this?
setTimeout('redirect()', 0)
?
you don't have a function called redirect or did you just skip that part when you showed your script?
ez4me2c3d
01-25-2003, 05:23 PM
the setimeout is not needed, and you have a `}` in there that should not be there.
just good coding practice you should end every statement with an `;` like so
parent.location.href = randomlinks[Math.floor(Math.random()*randomlinks.length)];
so this would be all you need. (Tested)
var randomlinks=new Array("http://freewarejava.com", "http://javascriptkit.com", "http://dynamicdrive.com", "http://cnn.com", "http://www.geocities.com");
location.href = randomlinks[Math.floor(Math.random()*randomlinks.length)];
angiras
01-26-2003, 08:37 AM
thank you to all of you , It works !
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.