Technology Talks > Programming
Javascript to load random links with html
(1/1)
Admin:
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: ---<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> </h2>
<body onLoad="javascript:randomlink()" >
<!--Uncomment below to use a regular text link instead
<a href="javascript:randomlink()">Random Link</a>
-->
--- End code ---
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.
Navigation
[0] Message Index
Go to full version