Advertisement

Javascript to load random links with html

 (Read 7876 times)

Admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1549
    • The Jucktion
Javascript to load random links with html
« on: Sep 05, 2010, 05:27 PM »
If you want to load a random link every single time your html page opens you can use this javascript code to do that for you.

Code: [Select]
<meta http-equiv="Content-Language" content="en-us">
<script>
<!--
/*
Random link button- By JavaScript Kit (http://javascriptkit.com)
Over 300  free scripts!
This credit MUST stay intact for use
*/

//specify random links below. You can have as many as you want
var randomlinks=new Array()
randomlinks[7]="http://jucktion.com/"
randomlinks[6]="http://jucktion.com/forum/"
randomlinks[5]="http://jucktion.com/forum/programming/"
randomlinks[4]="http://jucktion.com/forum/softwares/"
randomlinks[3]="http://jucktion.com/forum/webmasters-talk/"
randomlinks[2]="http://jucktion.com/forum/mobile-and-wireless/"
randomlinks[1]="http://jucktion.com/forum/webmasters-tutorials/"
randomlinks[0]="http://jucktion.com/forum/search-engine-optimization(seo)/"

function randomlink(){
window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
}
//-->
            </script>&nbsp;</h2>
<body onLoad="javascript:randomlink()" >

<!--Uncomment below to use a regular text link instead
<a href="javascript:randomlink()">Random Link</a>
-->

What this does is loads the links in arrays and then when the body loads, the  javascript executes and a random link opens up every single time.
You can use the code right away in a html page with your urls. If you want more url in the list you can just add 1 more between the randomlinks like
randomlinks[8]="http://yoursite.com/yourlink/"

and youre random page is done.