Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nitromaster

macrumors 6502
Original poster
Jan 7, 2007
334
0
Ireland.
Bit lost here.....

I need some javascript that when clicked brings you to an url with a random number at the end,

Something like
www.somesite.com/userid= and then the random number.

I cannot figure out how to do it myself, nor can find any guides on how to do something similar.
Any guides for random urls ive found require you to make a list of each url.


Any help?
 
I take it your not a programmer as this is very simple to do. Here is a sample script I made that generates a random number between 0 and 100 for the user id, then simple appends it to the base link.

<HTML>
<HEAD></HEAD>

<BODY>

<script type="text/javascript">

function random_link(){

var random_num=Math.round(Math.random()*101)
var base_link="http://www.blah.com/userid="
var targetlink= base_link + random_num;
window.location=targetlink
}
</script>

<a href="JavaScript:random_link()">Random link</a>

</BODY>
</HTML>
 
HTML:
<script type="text/javascript">
function randLink()
{
     var minVal=1000;
     var maxVal=2000;
     var userId=Math.round((Math.random()*(maxVal-minVal))+minVal);
     var link="http://yoursite.com/userid=";
     window.location=link+userId;
}
</script>

<a href="javascript:randLink()">Random link</a>

where minVal is your minimum value, maxVal is your maximum value and link is the website address.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.