View Full Version : Random sites with javascript .......?
MoshMetal
06-15-2001, 04:46 PM
I need some help from you guys.
I am searching a javascript that automatically switch between 2 starting pages.
Means that shows randomly the pages by entry.
Any idea?
thanx for your help
this does the job - but does not represent my best work...
if (Math.floor(Math.random()*100)<50)
{
document.write('<meta http-equiv="refresh" content="0;URL=site1.html">');
}
else
{
document.write('<meta http-equiv="refresh" content="0;URL=site2.htm">');
}
rukbunker
06-16-2001, 07:06 AM
Turf..
how does that work. I can't it..
Simon
06-16-2001, 12:53 PM
Its simple .. he is using the random function of the math library of javascript for the script to generate a random number.. if the random number which is between 0 and 100 larger then 50 then it opens the first url
if its smaller then opens the second url. doesn't take a rocket scientist to figure that out =)
I found this javascript a while back on this board.
<script language=JavaScript>
<!-- Begin
var howMany = 3; // max number of items listed below
var page = new Array(howMany+1);
page[0]="links.shtml";
page[1]="links1.shtml";
page[2]="links2.shtml";
page[3]="links3.shtml";
function rndnumber(){
var randscript = -1;
while (randscript < 0 || randscript > howMany || isNaN(randscript)){
randscript = parseInt(Math.random()*(howMany+1));
}
return randscript;
}
quo = rndnumber();
quox = page[quo];
window.location=(quox);
// End -->
</script>
MoshMetal
06-16-2001, 01:09 PM
thanx for your help.
I will try both out and see which works best for me.
vBulletin® v3.7.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.