SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ids to go with my banner rotations?

    hey, i wrote some banner rotation code, and i want the ID to change with it's corresponding banner. (the ID is for PHP to keep track of certain banner click throughs)

    here's the code:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
        <title>Untitled</title>
        <script language="javascript">
        
            function BannerChanger() {
        
            totalBanners=6;
            var theImages=new Array();
            theImages[0]="01.gif";
            theImages[1]="02.gif";
            theImages[2]="03.gif";
            theImages[3]="04.gif";
            theImages[4]="05.gif";
            theImages[5]="06.gif";
            
            var theIDs=new Array();
            theIDs[0]=6;
            theIDs[1]=7;
            theIDs[2]=8;
            theIDs[3]=9;
            theIDs[4]=10;
            theIDs[5]=11;
            
            if('undefined'==typeof(i)) {
            i=0;
            }
            
                    document.bannerOne.src = theImages[i];
                    i++;
                    if ((i+1)>=totalBanners) {
                    i=0;
                    }
                    setTimeout("ReStart()", 1000);
            }
            
            function ReStart() {

                 setTimeout("BannerChanger()", 9000);
                
            }
            

        </script>
    </head>

    <body onload="BannerChanger()">

    <a href="<? echo "$PHP_SELF?action=track&ID="?><script language="javascript">PUT ID HERE</script>"><img name="bannerOne" src="" width="468" height="60" alt="" border="0"></a>


    </body>
    </html>

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Give the <a> an ID, and then you can do whatever you want with it's properties

    Example:
    Code:
    <html>
      <head>
        <script language="javascript">
          var id = 0;
          function changeurl()
          {
            var link = document.getElementById("mylink");
            var href = link.href;
            var pos = href.indexOf("ID=") + 3;
            href = href.substr(0, pos) + id;
            link.href = href; 
            if(confirm("The href is now:\n" + href + "\n\nContinue?"))
            {
              id = ++id % 10;
              setTimeout("changeurl()", 1000);
            }
          }
        </script>
      </head>
      <body onload="changeurl();">
        <a id="mylink" href="http://www.fakeurl.com/somepage.php?ID=">Hi, I'm the link</a>
      </body>
    </html>

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice. does that work in netscape 4, too?

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Spidergrant
    nice. does that work in netscape 4, too?
    No, it's only working in real browsers

    OK, you could grab the <a> tag like this in the NS case...

    Code:
    <html>
      <head>
        <script language="javascript">
          var ns4 = (document.layers);
          if((ns4) && confirm("You're using an obsolete browser.\n\nUpgrade now?"))
          {
            location.href = "http://www.mozilla.org";
          }
          var id = 0;
          function changeurl()
          {
            if(ns4)
            {
              var link = document.links[0];
            }
            else
            {
              var link = document.getElementById("mylink");
            }
            var href = link.href;
            var pos = href.indexOf("ID=") + 3;
            href = href.substr(0, pos) + id;
            link.href = href; 
            if(confirm("The href is now:\n" + href + "\n\nContinue?"))
            {
              id = ++id % 10;
              setTimeout("changeurl()", 1000);
            }
          }
        </script>
      </head>
      <body onload="changeurl();">
        <a id="mylink" href="http://www.fakeurl.com/somepage.php?ID=">Hi, I'm the link</a>
      </body>
    </html>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •