View Full Version : Random number in link?
kgpbeyond
03-13-2004, 10:52 PM
Okay, is it possible to have a random number in a link? So like, if I load a page it has a link on it and I click the link and it takes me to a different place depending on the random number within the link? like say the link is to:
secret.php?result=randomnumber&layout=plain
is it possible to do something like that so that every time you load the first page the link to secret.php is different with the random number?
sidney
03-13-2004, 11:03 PM
echo"<a href=\"serverinfo.html?result=".Rand(1,100)."&LAYOUT=PLAIN\">SOMETEXT</a>";
HOPE THAT HELPS
RAND(1,100) GENERATES A NUMBER BETWEEN 1 AND 100
kgpbeyond
03-13-2004, 11:49 PM
hmm.... actually, I just realized the server doesn't support php... which sucks 'cause now I can't toss on the message board I wanted, but that aside, is there anyway to accomplish these results using HTML/javascript? :-P Guess I tossed this ***** in the wrong forum afterall. heh
Serex
03-14-2004, 12:06 AM
Ok i never done this before and will be just throwing some ideas around.
var randomnumber=Math.floor(Math.random()*1001)
function var_link(varible_value) {
new_win = window.open('http://www.yourpage.com/'+varible_value+','', 'width=640,height=400,left=10,top=10')
}
<a href="javascript:var_link('randomnumber')">Test</a>
Ok i havent tested it but if it doesnt work tell me and ill have another go.
kgpbeyond
03-14-2004, 02:11 AM
nope doesn't work :-( Not sure why, either. I mean.... the link doesn't do anything at all... doesn't bring up an error, doesn't open a new window... nothin'
Serex
03-14-2004, 07:07 AM
Ok ive sat down for 5mins and had a look at it. Ive got it working. Enjoy
<script language="JavaScript">
function var_link(varible_value) {
var randomnumber=Math.floor(Math.random()*1001)
new_win = window.open('http://www.yoursite.com.au/'+randomnumber+'')
}
</script>
<a href="javascript:var_link('randomnumber')">Test</a>
example @ here (http://www.modelmania.com.au/rand.htm)
kgpbeyond
03-14-2004, 03:26 PM
alright, awesome, it works, but one question, is it possible to set a range of values for the random number to come from? I thought that putting Math.random(0,20000) would do the trick, but it just yields 0 all the time
Oh, how does one open it in the same window? :-P sorry, it's been awhile since I've done any web design.
Serex
03-15-2004, 04:18 AM
var randomnumber=Math.floor(Math.random()*1001)
if you want to set the range then change the 1001 to say 200001 ect. :p
now for the window opening in self just use self as the location. i.e
new_win = self.location.href='http://www.yoursite.com.au/'+randomnumber+'';
kgpbeyond
03-15-2004, 03:24 PM
ah, thankies :-) sorry for my ignorance :-P
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.