WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 setTimeout bug in my Link Rotator, Guilherme Blanco, October 5, 2003
     Re:setTimeout bug in my Link Rotator, Erik Arvidsson, October 5, 2003

Subject: setTimeout bug in my Link Rotator From: Guilherme Blanco Date: October 5, 2003

Hi... tonight I've been trying to create a better code for my currently Link Rotator. I tryed to create a OOP code finally (my old one was terrible and supports only one linkrotator per page).
But, it returns me that he can't find the update method of the object. Check out this whole source of example:

<html>
  <head>
    <title>Link Rotator</title>
    <style>
      A.linkrotator:link { text-decoration: none; color: black; font-weight: bold; }
      A.linkrotator:visited { text-decoration: none; color: black; font-weight: bold; }
      A.linkrotator:active { text-decoration: none; color: black; font-weight: bold; }
      A.linkrotator:hover { text-decoration: none; color: orange; font-weight: bold; }
    </style>

    <script>
      function grabElement( sId ) {
        if(document.getElementById) { return document.getElementById(sId); }
        else { if(document.all) { return document.all[sId]; }
        else { return document.layers[sId]; } }
      }

      function LinkRotator() {
        for( var i = 1; ; i++ ) { if( ! grabElement("linkRotator"+i) ) { break; } }
        document.write("<div id=\"linkRotator"+i+"\">&nbsp;</div>");
        this.links = [];
        this.timer = 2;
        this.counter = this.pointer = -1;
        this.identifier = "linkRotator"+i;
      }

      LinkRotator.prototype.add = function( sText, sURL ) {
        this.links[++this.counter] = new Array( sText, sURL );
      }

      LinkRotator.prototype.update = function( ) {
        if( ++this.pointer == this.counter + 1 ) { this.pointer = 0; }
        grabElement(this.identifier).innerHTML = "<A CLASS='linkrotator' HREF='"+ this.links[this.pointer][1]+"'>"+ this.links[this.pointer][0] +"</A>";
        this.change();
      }

      LinkRotator.prototype.init = function ( ) { this.update(); }

      LinkRotator.prototype.change = function( ) { window.setTimeout("this.update()", this.timer*1000); }
    </script>
  </head>

  <body>
    <script>
      var link = new LinkRotator();
      link.add("Test 1", "
http://www.pontukom.com");
      link.add("Test 2", "
http://www.pontukom.com");
      link.add("Test 3", "
http://www.pontukom.com");
      link.add("Test 4", "
http://www.pontukom.com");
      link.add("Test 5", "
http://www.pontukom.com");
      link.add("Test 6", "
http://www.pontukom.com");
      link.init();
    </script>
  </body>
</html>

Please, can anyone tell me the bug here???

Cheers,
Guilherme Blanco




Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX