View Full Version : Javascript to display random page?
Nitromaster
Dec 1, 2007, 06:02 PM
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?
devpro
Dec 2, 2007, 04:13 PM
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>
Nitromaster
Dec 9, 2007, 02:08 PM
Thanks :D
What if you want it to pick a random number between say 1000 and 2000?
yagran
Dec 9, 2007, 03:50 PM
<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.
vBulletin® v3.6.10, Copyright ©2000-2009, Jelsoft Enterprises Ltd.