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

Ad rotator script that rotates every page load?

Discussion in 'HTML & JavaScript' started by wakkaoaka, May 19, 2009.

  1. wakkaoaka

    wakkaoaka BANNED BANNED

    Joined:
    Sep 14, 2008
    Messages:
    1,113
    Likes Received:
    782
    Does anyone know where i can find an ad rotator html or javascript that rotates every time a page is loaded rather than every (x) seconds? I tried googling but to no avail, i always find javascript ad rotators that are rotate ads on a timer.

    Whatever Diamond Dave is using on bhw :> I would love the code.
     
  2. specopkirbs

    specopkirbs BANNED BANNED

    Joined:
    Nov 28, 2008
    Messages:
    920
    Likes Received:
    746
    for wordpress there is max banner ads
     
  3. wakkaoaka

    wakkaoaka BANNED BANNED

    Joined:
    Sep 14, 2008
    Messages:
    1,113
    Likes Received:
    782
    Im using a phpbb3 forum.
     
  4. s0phia

    s0phia Regular Member

    Joined:
    Nov 11, 2008
    Messages:
    266
    Likes Received:
    280
    ctrl + u

    Code:
    <script type="text/javascript">
    <!-- Begin
    rnd.today=new Date();
    rnd.seed=rnd.today.getTime();
    
    function rnd() {
            rnd.seed = (rnd.seed*9301+49297) % 233280;
            return rnd.seed/(233280.0);
    };
    
    function rand(number) {
    	var result = Math.ceil(rnd()*number);
    	if (!result)result++;
            return result
    };
    var ad_cnta = 5;
    var ada = rand(ad_cnta);
    var linka;
    var adBannera;
    var widtha
    var heighta
    if (ada==1) {
    linka="http://www.google.com";
    adBannera="Link 1";
    }
    if (ada==2) {
    linka="http://www.google.com";
    adBannera="Link 2";
    }
    if (ada==3) {
    linka="http://www.google.com";
    adBannera="Link 3";
    }
    if (ada==4) {
    linka="http://www.google.com";
    adBannera="Link 4";
    }
    if (ada==5) {
    linka="http://www.google.com";
    adBannera="Link 5";
    }
    document.write('<center><a style="font-size:20px;color:#FFCC00;font-family:verdana;font-weight:bold;" href="' + linka + '" target="_top">');
    document.write(adBannera + '</a>');
    document.write('</center>');
    // End -->
    </SCRIPT>
    
     
    • Thanks Thanks x 2
  5. wakkaoaka

    wakkaoaka BANNED BANNED

    Joined:
    Sep 14, 2008
    Messages:
    1,113
    Likes Received:
    782
    What would i do without bhw... Thank you Sophia. It works, although i noobed it out and am put the affiliate image links which are .dat in the image links. Now time to change them to the .jpg or whatever the image formats are.
     
  6. wakkaoaka

    wakkaoaka BANNED BANNED

    Joined:
    Sep 14, 2008
    Messages:
    1,113
    Likes Received:
    782
    Oh i made a mistake.
    Code:
    linka="http://www.google.com";
    adBannera="Link 1";
    }
    if (ada==2) {
    linka="http://www.google.com";
    adBannera="Link 2";
    }
    if (ada==3) {
    linka="http://www.google.com";
    adBannera="Link 3";
    }
    if (ada==4) {
    linka="http://www.google.com";
    adBannera="Link 4";
    }
    if (ada==5) {
    linka="http://www.google.com";
    adBannera="Link 5";
    I figured the adBannera="link5" was where i put the image link got the banner? Or do i put the full a href banner link in the linka line? Everythings working well, just the banner isnt showing the images, just the image address.
     
  7. s0phia

    s0phia Regular Member

    Joined:
    Nov 11, 2008
    Messages:
    266
    Likes Received:
    280
    yer i only took the script that is in place here. you hav to modify the document.write:

    Code:
    document.write('<a href="' + linka + '" target="_top"><img src="');
    document.write(adBannera + '" /></a>');
     
    • Thanks Thanks x 1
    Last edited: May 20, 2009
  8. justmeron

    justmeron Power Member

    Joined:
    Sep 16, 2007
    Messages:
    752
    Likes Received:
    211
    Location:
    Indiana, USA
    there are a lot of programmers here. Some have told me this is a simple script. If you can't find it here for free IMO someplace like rent a coder, you could get one pretty cheap. That is if you dont get this one working for you.
    :)
     
    • Thanks Thanks x 1
  9. neta1o

    neta1o Regular Member

    Joined:
    Sep 29, 2008
    Messages:
    388
    Likes Received:
    318
    Home Page:
    • Thanks Thanks x 2
  10. wakkaoaka

    wakkaoaka BANNED BANNED

    Joined:
    Sep 14, 2008
    Messages:
    1,113
    Likes Received:
    782
    Heres my final one, it didnt work though. I noticed one thing i can fix and that is the width and height, it should be on separate lines with the widtha and heighta rather than in the abanner line.

    Hopefully it will work when i fix the height/width.
    Code:
    <script type="text/javascript">
    <!-- Begin
    rnd.today=new Date();
    rnd.seed=rnd.today.getTime();
    
    function rnd() {
            rnd.seed = (rnd.seed*9301+49297) % 233280;
            return rnd.seed/(233280.0);
    };
    
    function rand(number) {
    	var result = Math.ceil(rnd()*number);
    	if (!result)result++;
            return result
    };
    var ad_cnta = 5;
    var ada = rand(ad_cnta);
    var linka;
    var adBannera;
    var widtha
    var heighta
    if (ada==1) {
    linka="http://www.link1.com";
    adBannera="http://www.linkimage1.com"  width=728 height=90 border=0;
    }
    if (ada==2) {
    linka="http://www.link2.com";
    adBannera="http://www.linkimage2.com"  width=728 height=90 border=0;
    }
    if (ada==3) {
    linka="http://www.link3.com";
    adBannera="http://www.linkimage3.com"  width=728 height=90 border=0;
    }
    if (ada==4) {
    linka="http://www.link4.com";
    adBannera="http://www.linkimage4.com"  width=728 height=90 border=0;
    }
    if (ada==5) {
    linka="http://www.link5.com";
    adBannera="http://www.linkimage5.com"  width=728 height=90 border=0;
    }
    document.write('<a href="' + linka + '" target="_top"><img src="');
    document.write(adBannera + '</a>');
    document.write('</center>');
    // End -->
    </SCRIPT>
     
  11. wakkaoaka

    wakkaoaka BANNED BANNED

    Joined:
    Sep 14, 2008
    Messages:
    1,113
    Likes Received:
    782
    Thanks for the rotator net01, but i dont need it now, nearly got this one figured out. It is now rotating with the image. Problem is the image cannot be located, Probably due to the document.write or something. I deleted my height and width parameters and border.

    Edit: Yup everything is sorted, except the image is broken.

    Edit2:
    Ok the images work with this document.write code, its all rotating fine. Although, the affiliate link(the link is clickable too) is showing up next the the banner like this:
    [​IMG]
    And heres the document.write code im currently using:
    Code:
    document.write('<center><a href="' + linka + '" target="_top"><img src="' + adBannera + '">');
    document.write(adBannera + '</a>');
    document.write('</center>');
     
    Last edited: May 20, 2009
  12. wakkaoaka

    wakkaoaka BANNED BANNED

    Joined:
    Sep 14, 2008
    Messages:
    1,113
    Likes Received:
    782
    sorry for the multipost, just ran out of time to edit my last post :< heres my final edit:

    Final edit:

    Yus its working now. I removed the second line of the document.write code:
    Code:
    document.write(adBannera + '</a>');
    now this is my final rotation code for anyone else who wants to copy:
    Code:
    <script type="text/javascript">
    <!-- Begin
    rnd.today=new Date();
    rnd.seed=rnd.today.getTime();
    
    function rnd() {
            rnd.seed = (rnd.seed*9301+49297) % 233280;
            return rnd.seed/(233280.0);
    };
    
    function rand(number) {
    	var result = Math.ceil(rnd()*number);
    	if (!result)result++;
            return result
    };
    var ad_cnta = 5;
    var ada = rand(ad_cnta);
    var linka;
    var adBannera;
    var widtha
    var heighta
    if (ada==1) {
    linka="http://www.link1.com";
    adBannera="http://www.imagelink1.com";
    }
    if (ada==2) {
    linka="http://www.link2.com";
    adBannera="http://www.imagelink2.com";
    }
    if (ada==3) {
    linka="http://www.link3.com";
    adBannera="http://www.imagelink3.com";
    }
    if (ada==4) {
    linka="http://www.link4.com";
    adBannera="http://www.imagelink4.com";
    }
    if (ada==5) {
    linka="http://www.link5.com";
    adBannera="http://www.imagelink5.com";
    }
    document.write('<center><a href="' + linka + '" target="_top"><img src="' + adBannera + '">');
    document.write('</center>');
    // End -->
    </SCRIPT>
     
  13. wakkaoaka

    wakkaoaka BANNED BANNED

    Joined:
    Sep 14, 2008
    Messages:
    1,113
    Likes Received:
    782
    Sorry dont use the script from the post above. The <a href> tag wasnt closed so my banner link leaked through the rest of the page resulting in me not being able to log into my admin control panel (the login box would just link to the advertisment lol). Had to delete the cache manually.

    Use this code instead:

    Code:
    <script type="text/javascript">
    <!-- Begin
    rnd.today=new Date();
    rnd.seed=rnd.today.getTime();
    
    function rnd() {
            rnd.seed = (rnd.seed*9301+49297) % 233280;
            return rnd.seed/(233280.0);
    };
    
    function rand(number) {
    	var result = Math.ceil(rnd()*number);
    	if (!result)result++;
            return result
    };
    var ad_cnta = 5;
    var ada = rand(ad_cnta);
    var linka;
    var adBannera;
    var widtha
    var heighta
    if (ada==1) {
    linka="http://www.link1.com";
    adBannera="http://www.imagelink1.com";
    }
    if (ada==2) {
    linka="http://www.link2.com";
    adBannera="http://www.imagelink2.com";
    }
    if (ada==3) {
    linka="http://www.link3.com";
    adBannera="http://www.imagelink3.com";
    }
    if (ada==4) {
    linka="http://www.link4.com";
    adBannera="http://www.imagelink4.com";
    }
    if (ada==5) {
    linka="http://www.link5.com";
    adBannera="http://www.imagelink5.com";
    }
    document.write('<center><a href="' + linka + '" target="_top"><img src="' + adBannera + '">');
    document.write('</a>');
    document.write('</center>');
    // End -->
    </SCRIPT>
     
  14. silenze

    silenze Newbie

    Joined:
    Aug 13, 2008
    Messages:
    37
    Likes Received:
    21
    Occupation:
    IM
    Location:
    Mexico
    Home Page:
    this might work for you if you have a hard time getting that to work

    Code:
    http://www.devdude.com/tools/js/adrotator/
    just add your links and it will create the javascript for you
     
    • Thanks Thanks x 1
  15. Rendias

    Rendias Registered Member

    Joined:
    May 14, 2009
    Messages:
    91
    Likes Received:
    34
    that's a great share silenze!