Ejemplos en Javascript

Ring de sitios con botones en Javascript

Este script permite crear un ring, es decir una serie de sitios conectados en forma de anillo, mediante tres botones en javascript: previous, next, random

<HTML>
<HEAD>

<TITLE>Ejemplos Javascript: ejemplo pr???¡ctico </TITLE>

<SCRIPT LANGUAGE="JavaScript">
<!--- hide script from old browsers
// You can add as many site as you want, but this script must be in the head of each site,
//and the buttons must be on each site as well.
//Script by Qirien Dhaela, http://www.geocities.com/Area51/Corridor/2451/index.html,qirien@earthling.net
//This script may be used for nonprofit, non-commercial, or educational use as long as these
//comment lines remain intact and the basic script is not changed.

// The sites in the Webring (substitute your own!)
sites = new Array()
sites [1] = "http://www.myalgorithm.com"
sites [2] = "http://www.myalgorithm.com/some1"
sites [3] = "http://www.myalgorithm.com/some2"
sites [4] = "http://www.myalgorithm.com/some3"


var max=sites.length-1, place=0

function findthis() {
// find which site the user is currently on
        thisURL=document.URL.toLowerCase();
        for (var i=1; i<=max; i++){
                if (thisURL==sites[i])
                        place=i;
}
}

function go(where) {
// go to a site
        location = sites[where];
}

function next() {
// go to the next site
        findthis();
        if (place==max)
                place=1;
        else
                place=place+1;
        go(place);
}

function previous() {
// go to the previous site
        findthis();
        if (place<=1)
                place=max;
        else
                place=place-1;
        go(place);
}

function getRandom() {
// get a random number
   return Math.random()
}

function random() {
// go to a random site
        findthis();
        myrand=Math.round(getRandom()*(max));
        if ((place==myrand) || (myrand==0))
                random();
        else {
                place=myrand;
                go(place);             
}
}
       
// end hiding from old browsers -->
</SCRIPT>


</HEAD>

<BODY bgcolor="white">


<FORM NAME="aform">
<Input type="button" value="Previous" onClick="previous()">    
<Input type="button" value="Next" onClick="next()">    
<INPUT TYPE="Button" value="Random" onClick="random()">
</FORM></center>

</body>
</html>

Botones