Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Rotating Banner Ad

    I am using this rotating banner ad script, but was wondering if its possible to add a timer like every 30 seconds it changes to the next banner without having to refreshing the page.

    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    var how_many_ads = 3;
    var now = new Date()
    var sec = now.getSeconds()
    var ad = sec % how_many_ads;
    ad +=1;
    if (ad==1) {
    txt="TEXTO QUE PONDRAS";
    url="URL DEL WEB";
    alt="NOMBRE DEL WEB";
    banner="URL DEL BANNER";
    width="MEDIDA";
    height="MEDIDA";
    }
    if (ad==2) {
    txt="SOBRE LA WEB";
    url="URL DE LA WEB";
    alt="NOMBRE DE LA WEB"A;
    banner="http://etc, etc";
    width="MEDIDAS";
    height="MEDIDAS";
    }
    if (ad==3) {
    txt="SOBRE LA WEB";
    url="URL DE LA WEB";
    alt="NOMBRE DE LA WEB ";
    banner="http://URL DEL BANNER";
    width="MEDIDAS";
    height="MEDIDAS";
    }
    document.write('<center>');
    document.write('<a href=\"' + url + '\" target=\"_blank\">');
    document.write('<img src=\"' + banner + '\" width=')
    document.write(width + ' height=' + height + ' ');
    document.write('alt=\"' + alt + '\" border=0><br>');
    document.write('<small>' + txt + '</small></a>');
    document.write('</center>');
    // End -->
    </SCRIPT>

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Try something on these lines

    Code:
    <script type="text/javascript"> 
    
    adds=[ // txt, url,alt,image
    
    ["TEXTO QUE PONDRAS","URL DEL WEB","NOMBRE DEL WEB","URL DEL BANNER"],
    
    ["SOBRE LA WEB","URL DE LA WEB","NOMBRE DE LA WEB"A","http://etc, etc"], 
    
    ["SOBRE LA WEB","URL DE LA WEB","NOMBRE DE LA WEB ","http://URL DEL BANNER"]
    
    ]
    
    count=0
    onload=function test(){
    
    oLink=document.getElementById("mylink")
    oImg=document.getElementById("myimg")
    oTxt=document.getElementById("mytxt")
    
    oTxt.innerHTML=adds[count][0]
    oLink.href=adds[count][1]
    oImg.alt=adds[count][2]
    oImg.src=adds[count][3]
    
    count++
    if(count==adds.length){
    count=0
    }
    
    setTimeout("test()",30000)
    }
    
    </script>
    
    
    <a id="mylink" href="#null" target="_blank"><img id="myimg" src="" alt="" style="width:300px;height:150px"><div id="mytxt"></div></a>
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • Users who have thanked Mr J for this post:

    CBaZ (06-16-2008)

  • #3
    New Coder
    Join Date
    Jun 2008
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts
    that works for 3 ads once I add more I have 22 right now it says #null and no images are displayed. is there anything I must add?

  • #4
    New Coder
    Join Date
    Jun 2008
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts
    nevermind I found my own bugs great script only thing i wish it could do is load them i random order

    then this would be the ultimate script

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    count = Math.floor(Math.random()*adds.length);

  • Users who have thanked Philip M for this post:

    CBaZ (06-16-2008)

  • #6
    New Coder
    Join Date
    Jun 2008
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thanks for this great script. its working great.

  • #7
    New Coder
    Join Date
    Jun 2008
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts
    if i wanted to have this script work at 2 different places is that possible. I have 468X60 banners in another place that I would like to rotate as well but if i use the same script it only works with one coding at a time.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    You cannot have two (or more) scripts with the same variable or function names, as the second simply overwrites the first.

    You need to rename all the variables and functions in the second script to adds2, count2, test2, oLink2, oImg2 and so on.

  • #9
    New Coder
    Join Date
    Jun 2008
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts
    It doesn't wanna do it for me I think I am missing something
    <code>

    <script type="text/javascript">

    adds2=[ // txt, url,alt,image

    ["txt","url","alt","image"],


    ["txt","url","alt","image"],

    ["txt","url","alt","image"],

    ["txt","url","alt","image"]

    ]

    count2=0
    onload=function test2(){

    oLink2=document.getElementById("mylink2")
    oImg2=document.getElementById("myimg2")
    oTxt2=document.getElementById("mytxt2")

    oTxt2.innerHTML2=adds2[count2][0]
    oLink2.href2=adds2[count2][1]
    oImg2.alt2=adds2[count2][2]
    oImg2.src2=adds2[count2][3]

    count2++
    if(count2==adds2.length){
    count2=0
    }

    setTimeout("test2()",30000)
    }

    </script>
    <center><font face=Verdana size=1 color="#f6eed0"><b><br>&nbsp;&nbsp;
    <a id="mylink2" href="#null" target="_blank"><img id="myimg2" src="" alt="" style="width:468px;height:60px" border="0"></a><div id="mytxt2"></center></div></font></b>

    </code>

  • #10
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    You had this typo:
    Code:
    oTxt2.innerHTML2=adds2[count2][0]
    oLink2.href2=adds2[count2][1]
    oImg2.alt2=adds2[count2][2]
    oImg2.src2=adds2[count2][3]
    This part is also erroneous:
    Code:
    onload=function test2(){
    You might mean like this instead:
    Code:
    function test()
    {...}
    
    
    
    
    window.onload=test2;
    To fully apply those notes, this ammendments might help:
    Code:
    <script type="text/javascript"> 
    
    adds2=[ // txt, url,alt,image
    ["txt","url","alt","image"],
    ["txt","url","alt","image"],
    ["txt","url","alt","image"],
    ["txt","url","alt","image"]]
    count2=0
    function test2(){
    
    oLink2=document.getElementById("mylink2")
    oImg2=document.getElementById("myimg2")
    oTxt2=document.getElementById("mytxt2")
    
    oTxt2.innerHTML=adds2[count2][0]
    oLink2.href=adds2[count2][1]
    oImg2.alt=adds2[count2][2]
    oImg2.src=adds2[count2][3]
    
    count2++
    if(count2==adds2.length){
    count2=0
    }
    setTimeout("test2()",30000)
    }
    window.onload=test2;
    
    </script>
    Sidenote, center and font are deprecated elements.

    Hope it helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #11
    New Coder
    Join Date
    Jun 2008
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts
    i am still just getting no image, and php#null

    not sure as to why. maybe this needs a fix too.

    <a id="mylink2" href="#null" target="_blank"><img id="myimg2" src="" alt="" style="width:468px;height:60px" border="0"><div id="mytxt2"></div></a>

  • #12
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    First, you need to change the highlighted with the image you want:
    Code:
    adds2=[ // txt, url,alt,image
    ["txt","url","alt","image"],
    ["txt","url","alt","image"],
    ["txt","url","alt","image"],
    ["txt","url","alt","image"]]
    You don't have an image source in your markups, but that would'nt be a big deal if you don't wish to have a default image.
    Code:
    <img id="myimg2" src="" alt="" style="width:468px;height:60px" border="0">
    Hope it helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #13
    New Coder
    Join Date
    Jun 2008
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts
    yea I know what you mean have that and still get the results of #phpnull and of course no image. well it has a link opens a new window with my site in it.
    <code>
    <script type="text/javascript">

    adds2=[ // txt, url,alt,image

    ["Please Visit Our Sponsor!","http://click.linksynergy.com/fs-bin/click?id=4Rwcmxpy*cA&offerid=127265.10000425&subid=0&type=4","Gaiam.com","http://ad.linksynergy.com/fs-bin/show?id=4Rwcmxpy*cA&bids=127265.10000425&subid=0&type=4&gridnum=-1"],

    ["Please Visit Our Sponsor!","http://click.linksynergy.com/fs-bin/click?id=4Rwcmxpy*cA&offerid=128069.10000499&type=4&subid=0","Limoges Jewelry","http://216.130.96.82/Affiliates-images/freeshipSummer_468x60.gif"],

    ["Please Visit Our Sponsor!","http://www.riverbelle.com/reports/index.asp?s=aff64428","Riverbelle Online Casino","/banners/rbc_468x060_576.gif"]



    ]

    count2=0
    function test2(){

    oLink2=document.getElementById("mylink2")
    oImg2=document.getElementById("myimg2")
    oTxt2=document.getElementById("mytxt2")

    oTxt2.innerHTML=adds2[count2][0]
    oLink2.href=adds2[count2][1]
    oImg2.alt=adds2[count2][2]
    oImg2.src=adds2[count2][3]

    count2++
    if(count2==adds2.length){
    count2=0
    }
    setTimeout("test2()",30000)
    }
    window.onload=test2;

    </script>


    <a id="mylink2" href="#null" target="_blank"><img id="myimg2" src="" alt="" style="width:468px;height:60px" border="0"><div id="mytxt2"></div></a>
    <b><font face=Verdana size=1 color="#f6eed0">&nbsp;&nbsp; Please Visit Our Sponsor!</font></b>
    </code>

  • #14
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    It's working (for me), tested on both FF and IE. Not certain what else to suggest though
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #15
    New Coder
    Join Date
    Jun 2008
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts
    got it to work now... but when i add this line
    <code>
    count2 = Math.floor(Math.random()*adds2.length);
    </code>
    to randomize the banners i see the action it does i see 4 different images fly by then it stops. so its working but i would like to not see those rotating banners any suggestions you guys have been abig help


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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