Click to See Complete Forum and Search --> : Random Start Page
MyDogShotJFK
02-04-2003, 07:33 AM
Hey, I have a question?
Some sites have a script that choose a random page from the index page. Like StarWars.com and www.ilm.com. I was wondering if anyone knew how they do it. If you do, let me know.
thanks
Here is some code that will do that for you. Also, remember to specify a page in the body for those with javascript turned off...To add more or less, chage Math.random()*3 to Math.random()*numberofpages, and add or subtract else if (x == ?)'s.
<script type="text/javascript">
var x = Math.floor((Math.random()*3));
if (x == 1)
{
top.location = "1.htm";
}
else if (x == 2)
{
top.location = "2.htm";
}
else
{
top.location = "3.htm";
}
</script>
MyDogShotJFK
02-04-2003, 08:01 AM
Thanks soooo much. I'll try it out, and get back to you.
thanks again.:D
MyDogShotJFK
02-04-2003, 08:16 AM
It worked! hurray! Thanks soo much.
Glad it worked...One other thing to point out. Sites like starwars.com don't have differnet pages that they send you to, they simply have random elements on those pages. Not that it matters, but... :D
MyDogShotJFK
02-04-2003, 11:15 AM
Good point - but I figure'd it'd take super long to do that, and the more code on the one page, the more things that can go wrong.
What do you think? Should I do it the other way? What would the disadvantages and advantages be?
I'd say that you might as well go ahead and have separate pages, unless you are only trying to change something simple, like a picture, or some text, etc. If you are looking for totally different pages, just randomly directing them to those pages would probably be best.
MyDogShotJFK
02-05-2003, 05:59 AM
yeah ... I think I misunderstood what my co-worker wanted, I thought he wanted different coloured backgrounds and everything, but now it's just one picture, so I think I'll get a random picture script instead.
Thanks for your help.:D
Here, try this out to randomly generate a background image...
<script type="text/javascript">
var Pic = new Array()
Pic[0] = '1.gif'
Pic[1] = '2.gif'
Pic[2] = '3.gif'
var x = Math.floor((Math.random()*3));
if (x == 1)
{
document.body.background = Pic[0];
}
else if (x == 2)
{
document.body.background = Pic[1];
}
else
{
document.body.background = Pic[2];
}
</script>
MyDogShotJFK
02-05-2003, 10:54 AM
Thanks, I don't have a lot of time to try it out right now, but I'll try it soon, and get back to you.
Thanks again,
Amanda