1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How does this script work

Discussion in 'HTML & JavaScript' started by stoknee, Feb 2, 2009.

  1. stoknee

    stoknee Newbie

    Joined:
    Jan 26, 2009
    Messages:
    11
    Likes Received:
    5
    I found this text link rotator script and downloaded it but there were no instructions on installing it. Can somebody clue me in on what I need to do to get this script to work?


    Code:
    <SCRIPT LANGUAGE="JavaScript1.2">
    <!--
    
    //browser detect (fourth generation)
    
    var ns = (document.layers) ? 1 : 0;
    var ie = (document.all) ? 1 : 0;
    
    //You may add cells to the array,i.e: ar[3]="..." ,ar[4]="..." and so on
    
    var ar=new Array()
    ar[0]="<a href='url goes here'>text here</a>"
    ar[1]="<a href='url goes here'>text here</a>"
    ar[2]="<a href='url goes here'>text here</a>"
    
    var num=0;
    
    /*
    do not change the script below this line except for the period of time 
    function update is being called, i.e:function update is currently being called every
    2000 ms =2 second --change only this number!!!
    */
    
    function start()
    {
    setInterval("update()","2000")
    }
    
    function update()
    {
    display("ban",ar[num]);
     num++;
      if (num == ar.length) num = 0;
    }
    
    function display(id,text)
    {
      
     if(ns)
     {
      document[id].document.open()
      document[id].document.write(text)
      document[id].document.close()
     }  
    
    
     if(ie)
      
       document.all[id].innerHTML=text
    
    }
    
    
    
    
    
    // -->
    </SCRIPT>
    
    
    <body onLoad="start()">
    
    
    <!-- --><DIV align=center id="ban" style="position: absolute; top: 500; left: 250; z-index: 0">Loading...</DIV><!-- -->
     
  2. lord

    lord Junior Member

    Joined:
    Jan 21, 2009
    Messages:
    176
    Likes Received:
    251
    this part goes into your <head> </head> section of your html file

    Code:
    <SCRIPT LANGUAGE="JavaScript1.2">
    <!--
    
    //browser detect (fourth generation)
    
    var ns = (document.layers) ? 1 : 0;
    var ie = (document.all) ? 1 : 0;
    
    //You may add cells to the array,i.e: ar[3]="..." ,ar[4]="..." and so on
    
    var ar=new Array()
    ar[0]="<a href='url goes here'>text here</a>"
    ar[1]="<a href='url goes here'>text here</a>"
    ar[2]="<a href='url goes here'>text here</a>"
    
    var num=0;
    
    /*
    do not change the script below this line except for the period of time 
    function update is being called, i.e:function update is currently being called every
    2000 ms =2 second --change only this number!!!
    */
    
    function start()
    {
    setInterval("update()","2000")
    }
    
    function update()
    {
    display("ban",ar[num]);
     num++;
      if (num == ar.length) num = 0;
    }
    
    function display(id,text)
    {
      
     if(ns)
     {
      document[id].document.open()
      document[id].document.write(text)
      document[id].document.close()
     }  
    
    
     if(ie)
      
       document.all[id].innerHTML=text
    
    }
    
    
    
    
    
    // -->
    </SCRIPT>
    you replace the <body> tag of your html with
    Code:
    <body onLoad="start()">
    and this part wherever you want those link to appear
    Code:
    <DIV align=center id="ban" style="position: absolute; top: 500; left: 250; z-index: 0">Loading...</DIV>
    oh and as they say, don't forget about
    Code:
    ar[0]="<a href='url goes here'>text here</a>"
    ar[1]="<a href='url goes here'>text here</a>"
    ar[2]="<a href='url goes here'>text here</a>"
    change that url goes here to yoursite.com etc.