Random Link

liunx

Guest
Hi<br />
<br />
I have a fireworks site<br />
<br />
<!-- w --><a class="postlink" href="http://www.fireworks-2003.net">www.fireworks-2003.net</a><!-- w --> and was hope to add a link from the<br />
<br />
"Review page"<br />
<br />
That will link into a random page ofr eviews<br />
<br />
Is this possible in html and if so would anyone have any idea what i should do<br />
<br />
Thanks<!--content-->You can use Javascript:<script type="text/javascript"><br />
reviewpages = new Array(<br />
"review1.html",<br />
"review2.html",<br />
"review3.html",<br />
"");<br />
<br />
r = parseInt(Math.random()*(reviewpages.length-1));<br />
document.write('<a href=http://www.webdeveloper.com/forum/archive/index.php/"' + reviewpages[r] + '">Random Review</a>');<br />
</script><br />
Just change the URLs in the array or add to them as you need to.<br />
<br />
Adam<!--content-->Thanks for the quick reply Adamgundry i found this very helpful<!--content-->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<br />
<br />
r = parseInt(Math.random()*(reviewpages.length-1));<br />
<br />
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<br />
<br />
r = Math.floor(Math.random()*(reviewpages.length-1));<!--content-->Thanks Charles, I missed that one.<br />
<br />
Adam<!--content-->
 
Back
Top