Click to See Complete Forum and Search --> : Random Link


MotorMouth
06-03-2003, 05:31 AM
Hi

I have a fireworks site

www.fireworks-2003.net and was hope to add a link from the

"Review page"

That will link into a random page ofr eviews

Is this possible in html and if so would anyone have any idea what i should do

Thanks

AdamGundry
06-03-2003, 06:09 AM
You can use Javascript:<script type="text/javascript">
reviewpages = new Array(
"review1.html",
"review2.html",
"review3.html",
"");

r = parseInt(Math.random()*(reviewpages.length-1));
document.write('<a href="' + reviewpages[r] + '">Random Review</a>');
</script>
Just change the URLs in the array or add to them as you need to.

Adam

MotorMouth
06-03-2003, 06:17 AM
Thanks for the quick reply Adamgundry i found this very helpful

Charles
06-03-2003, 06:31 AM
There's one wee problem. And I do mean wee. The function parseInt() takes a string as its first parameter. That means that the line

r = parseInt(Math.random()*(reviewpages.length-1));

will first evaluate Math.random()*(reviewpages.length-1), returnning a number. The number will then be converted into the Number wrapper object and Number.toString() called. The line would be better written

r = Math.floor(Math.random()*(reviewpages.length-1));

AdamGundry
06-03-2003, 06:37 AM
Thanks Charles, I missed that one.

Adam