View Full Version : Random Link?


Gadget
06-01-2003, 09:04 AM
I'm hoping to find some script that enables the visitor to click a link that would then bring them to a random page. I use angelfire.com and they have a random script which changes on reload, but I am hoping for something random on click.
Any ideas? Thanks!:)

MaGiCSuN
06-01-2003, 01:03 PM
http://www.scriptarchive.com/rand_link.html

or look for more here:

http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=random+on+click+script

the url probably won't work from google , i'm sorry but this forum does some weird things with it lol.

Love,
Mirna

designhazard
06-01-2003, 02:14 PM
javascript version:
http://javascriptkit.com/javatutors/random2.shtml
http://javascriptkit.com/script/cut1.shtml

Gadget
06-02-2003, 10:23 PM
Wonderful! That's just what I needed, thank you! ;)

Gadget
06-05-2003, 07:13 AM
I've run into another problem...
I've found a great script:


<script type="text/javascript" language="javascript">
<!-- Code courtesy GurusNetwork.com
function gosomewhere(){
newlink = Math.floor(Math.random() * (links.length));
document.location = links[newlink];
}

var links = new Array(
'africanelephant_page.htm',
'gorilla_page.htm',
'manatee_page.htm',
'bebat_page.htm',
'blackrhino_page.htm'
);
//-->
</script>
<a href="#" onclick="gosomewhere();"><font face="Arial, Helvetica, sans-serif" size="3">Suprise
me!</font></a>


But I need to modify it so I can include 8 or more links! When I try to add new links into the script I'm getting an error and none of the random URL's work! :(

Dude128
06-06-2003, 12:37 AM
you should be able to just add them to the links array in the same format- separated by commas and in single quotes, since the script finds the number of elements automatically for you.

can you post your modified code if you still can't get it to work?

Gadget
06-06-2003, 05:52 AM
I'll give it another shot. Maybe I left the commas out! XD

Gadget
06-06-2003, 05:59 AM
Nope! Darn- I'd hoped it would be something simple like that! :p
Here's the html code for my page...


<html>
<head>
<title>The Endangered Adoption Agency</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000" link="#000000" vlink="#333333" alink="#333333">
<div align="center">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<p><b><font face="Comic Sans MS" size="2">Can't decide between our endangered
animals? Or perhaps you just want to leave it up to fate. </font></b></p>
<p><b><font face="Comic Sans MS" size="2">No problem! Click below to recieve
a random adoptee!</font></b></p>
</td>
</tr>
<tr>
<td>
<div align="center"> <font face="Comic Sans MS" size="4">
<script type="text/javascript" language="javascript">
<!-- Code courtesy GurusNetwork.com
function gosomewhere(){
newlink = Math.floor(Math.random() * (links.length));
document.location = links[newlink];
}

var links = new Array(
'/co4/endangeredadopt/african_elephant_page.htm',
'/co4/endangeredadopt/gorilla_page.htm',
'/co4/endangeredadopt/manatee_page.htm',
'/co4/endangeredadopt/bebat_page.htm',
'/co4/endangeredadopt/blackfootedferret_page.htm',
'/co4/endangeredadopt/chimpanzee_page.htm',
'/co4/endangeredadopt/blackrhino_page.htm',
'/co4/endangeredadopt/panda_page.htm',
);
//-->
</script>
<a href="#" onClick="gosomewhere();" target="mainFrame">Suprise me!</a>
</font></div>
</td>
</tr>
</table>
<p>&nbsp;</p>
</div>
<div align="center">
<div align="left">
<p>&nbsp; </p>
</div>
</div>
</body>
</html>


If you want to see it in action, you have to go to http://www.angelfire.com/co4/endangeredadopt/ie_eaa.htm
or if you use netscape, http://www.angelfire.com/co4/endangeredadopt/nn_eaa.htm Go down to "adoptions" then "suprise me" and it will bring up that page. Since I use frames I don't think I can give you the direct url for it.
Maybe that has something to do with the problem?
Anyway, thank you very much for your help, Lissa has the most informative website and forum!!

Gadget
06-06-2003, 06:04 AM
OMG I FINALLY GOT IT!!! *Runs around screaming happily*
It looks like I added another comma after the last link and that seemed to bugger it up!
*Gives Dude128 a big hug* Thank you so much!!
:D :D
It's working beautifully now!