# Some kinda script... :)



## Nummi_G4 (Feb 18, 2002)

Hey... any web geeks here know where I can get a javascript that will load a random page?  ex... go to nnn.blablabla.moc... and everytime you go there... you see a different splash page.


----------



## martinatkinson (Feb 18, 2002)

Hello!

I could cook something up for you.  Give me the URL's to the pages you want loaded and I will see what I can do.  I can not give you a script since the URL's get encoded in the actuall script to work.

Have a great day!

Albert


----------



## Nummi_G4 (Feb 19, 2002)

Hey, thanks a lot man 

The site is no where near to being finished, but I will keep you updated.  thanks again


----------



## martinatkinson (Feb 19, 2002)

You are very welcome, always glad to help a fellow web designer.  Let me know if you will need anything else.

Have a great day!

Albert


----------



## Nummi_G4 (Feb 23, 2002)

> _Originally posted by martinatkinson _
> *I can not give you a script since the URL's get encoded in the actuall script to work.
> *



there isn't a javascript that just picks a random page to go to... then re-directs you there?

(you go to the index page(that has the script) and within 1 sec it has already re-directed you to a random splash page.


----------



## martinatkinson (Feb 23, 2002)

Hello!

Go visit http://www.myfamilycenter.org/cjonline/ and see what happens.  You should be redirected to http://www.myfamilycenter.org/~cjonline/  Now look at the source of that page, your source will be primarily the same except for the fact that yours will be a random redirect to your splash pages.  Notice how there is alot of encrypted language as a source in the redirection page, that is why I will need your URL's, so I can encrypt them.

I am certain there are JavaScripts out on the web that you can find and if you want to do that go right ahead.  There are also CGI scripts at http://cgi.resourceindex.com/

Have a great day!

Albert


----------



## Nummi_G4 (Feb 24, 2002)

Do you know where I can get a javascript that can do that... not CGI ?


----------



## bighairydog (Feb 24, 2002)

Easy:
Just cahnge the bits to the real urls, and add or delete as many url's as you want, just make sure they're sequentially numbered

<script language="javascript"><!--
var foobar = new Array()

//change these values:
foobar[0] = "http://www.mindfiredesign.co.uk"
foobar[1] = "http://www.macosx.com"

// Do not edit past this line unless you are sure what you are doing.
var eatMe=Math.round((Math.random() * (foobar.length*0.999))-0.5)
document.location = foobar[eatMe]
//--></script>

Glad to be useful

Bernie     )


----------



## Nummi_G4 (Feb 24, 2002)

thanks so much...


but one thing... it does not seem to be totally random... it seems to have a favorite page it goes to.  I have 4 pages that it is supposed to randomly choose... it likes foobar[2].  in both IE and NN OS 9.


----------



## bighairydog (Feb 24, 2002)

&nbsp;&nbsp;&nbsp;&nbsp;I assure you it is. The human mind is notoriously bad at assessing randomness - R.A. Fisher (A great animal behaviour biologist) once asked people to write a random string of binary, and nobody had nearly enough long runs of just 1's or just 0's.

Say you have 4 entries, Follow the script through:

var eatMe=Math.round((Math.random() * (foobar.length*0.999))-0.5)

Math.random() generates a random number between 0 and 1
It is multiplied by the length of the foobar array: 4 in our case, to gave a number between 0 and 4
It is then multiplied by 0.999, a fix to make sure that the actual number 4 is never chosen (this would produce an error).
0.5 is subtracted from it, so as to give a number between -0.5 and 3.5
Math.Round() turns that into 0, 1, 2 or 3, with equal probability of each and that link is followed up.

I bet if you do it again you'll still notice a weird preference, but for different ones.


Bernie     )


----------



## bighairydog (Feb 24, 2002)

&nbsp;&nbsp;&nbsp;&nbsp;BTW, the more options you have, the more random it will seem, but it is always mathematically random.

&nbsp;&nbsp;&nbsp;&nbsp;Perhaps you'd like to make it so that it is deliberately non-random. The first one could be truely random, and then the next one is chosen from the ones that the viewer hasn't yet seen, and so on. This could be done with cookies, but I can't be arsed (LOL ;o)

Bernie      )


----------



## martinatkinson (Feb 24, 2002)

> _Originally posted by Nummi_G4 _
> *but one thing... it does not seem to be totally random... it seems to have a favorite page it goes to.*



Hello!

That is because this script only goes to one page.  I just wanted you to see about how it would work, about how fast and such.  The script I will do is pretty much the same but will randomly select a page.

Have a great day!

Albert


----------



## bighairydog (Feb 24, 2002)

Personally, I prefer my one to the golive version at www.myfamilycenter.org/cjonline/.

Golive writes appauling javascript, which is strange seeing as the program was written by programmers (obviously). This is GoLive's version of the one I made in the other post, and does the same.

Bernie     )


```
<csactionitem name="B88297090"></csactionitem>
		<csactions>
			<csaction name="B88297090" class="Goto Link" type="onload"
val0="http://www.myfamilycenter.org/~cjonline/" val1="">
		</csactions>
		<csscriptdict>
			<script><!--
CSInit = new Array;
function CSScriptInit() {
if(typeof(skipPage) != "undefined") { if(skipPage) return; }
idxArray = new Array;
for(var i=0;i<CSInit.length;i++)
	idxArray[i] = i;
CSAction2(CSInit, idxArray);}
CSStopExecution = false;
function CSAction(array) { 
	return CSAction2(CSAct, array);
}
function CSAction2(fct, array) { 
	var result;
	for (var i=0;i<array.length;i++) {
		if(CSStopExecution) return false; 
		var actArray = fct[array[i]];
		if (actArray == null) return false;
		var tempArray = new Array;
		for(var j=1;j<actArray.length;j++) {
			if((actArray[j] != null) && (typeof(actArray[j]) == "object") && (actArray[j].length == 2)) {
				if(actArray[j][0] == "VAR") {
					tempArray[j] = CSStateArray[actArray[j][1]];
				}
				else {
					if(actArray[j][0] == "ACT") {
						tempArray[j] = CSAction(new Array(new String(actArray[j][1])));
					}
				else
					tempArray[j] = actArray[j];
				}
			}
			else
				tempArray[j] = actArray[j];
		}			
		result = actArray[0](tempArray);
	}
	return result;
}
CSAct = new Object;

function CSGotoLink(action) {
	if (action[2].length) {
		var hasFrame=false;
		for(i=0;i<parent.frames.length;i++) { if (parent.frames[i].name==action[2]) { hasFrame=true; break;}}
		if (hasFrame==true)
			parent.frames[action[2]].location = action[1];
		else
			window.open (action[1],action[2],"");
	}
	else location = action[1];
}

// --></script>
		</csscriptdict>
		<csactiondict>
			<script><!--
CSInit[CSInit.length] = new Array(CSGotoLink,/*URL*/ 'http://www.myfamilycenter.org/~cjonline/','');

// --></script>
		</csactiondict>
	</head>

	<body bgcolor="#ffffff" onload="CSScriptInit();">
```


----------



## Nummi_G4 (Feb 27, 2002)

Is that using CSS too?


----------



## bighairydog (Feb 27, 2002)

Nope, it's just a very long bit of JavaScript that doesn't do the job very effectively...

Bernie     )


----------

