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

[GET] Simple Banner rotator script

Discussion in 'HTML & JavaScript' started by fbrcold, Jan 30, 2013.

  1. fbrcold

    fbrcold Junior Member

    Joined:
    Jul 13, 2008
    Messages:
    167
    Likes Received:
    305
    Occupation:
    Take a Guess
    Location:
    USA
    I looked forever to find a rotator script for my banners that i could use on my php sites, facebook apps, and wordpress. I had someone develop this for me and it works perfect so I am sharing it with the community. I think it is self explanatory.

    To change the size of the ads just change the size of width and height.

    I hope this helps some of you.
    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_cnt2 = 10;
    var ad2 = rand(ad_cnt2);
    var link2;
    var adBanner2;
    var width2
    var height2
    if (ad2==1) {
    link2="http://youraffiliatelink.com";
    adBanner2="http://yoursite.com/image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==2) {
    link2="http://youraffiliatelink.com";
    adBanner2="http://yoursite.com/image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==3) {
    link2="http://youraffiliatelink.com";
    adBanner2="http://yoursite.com/image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==4) {
    link2="http://youraffiliatelink.com";
    adBanner2="http://yoursite.com/image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==5) {
    link2="http://youraffiliatelink.com";
    adBanner2="http://yoursite.com/image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==6) {
    link2="http://youraffiliatelink.com";
    adBanner2="http://yoursite.com/image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==7) {
    link2="http://youraffiliatelink.com";
    adBanner2="http://yoursite.com/image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==8) {
    link2="http://youraffiliatelink.com";
    adBanner2="http://yoursite.com/image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==9) {
    link2="http://youraffiliatelink.com";
    adBanner2="http://yoursite.com/image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==10) {
    link2="http://youraffiliatelink.com";
    adBanner2="http://yoursite.com/image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    document.write('<center><a href="' + link2 + '" target="_blank">');
    document.write('<img src="' + adBanner2 + '" width=' + width2 + ' height=' + height2 + ' border=0 
    
    alt="' + alt2 + '"></a>');
    document.write('</center>');
    // End -->
    </SCRIPT>
    
     
    • Thanks Thanks x 4
  2. siju123

    siju123 Newbie

    Joined:
    Apr 4, 2016
    Messages:
    1
    Likes Received:
    0
    Thank you

    I need this
     
  3. sted8888

    sted8888 Newbie

    Joined:
    Feb 18, 2015
    Messages:
    2
    Likes Received:
    0
    its very easy, thank you:)
     
  4. smashingcreativez

    smashingcreativez Registered Member

    Joined:
    Dec 5, 2014
    Messages:
    85
    Likes Received:
    7
    Occupation:
    Saiyan
    Location:
    Earth
    Thank you for sharing will use for my future works :) .
     
  5. Harvest Golem

    Harvest Golem Newbie

    Joined:
    Aug 27, 2014
    Messages:
    35
    Likes Received:
    4
    Occupation:
    Project Manager
    Location:
    Moscow
    The script is good, but I don't understand why would this script generate a random number in such a complicated way..
    I mean all the crap at the top of the script where it gets Date, time, then multiplies it, randomizes, etc. - all this just to get a random number between 1 and 10.

    So I guess the simpler version of a script should be:

    Code:
    var ad2 = Math.floor((Math.random() * 10) + 1);
    var link2;
    var adBanner2;
    var width2
    var height2
    if (ad2==1) {
    link2="http://youraffiliatelink.com";
    adBanner2="image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==2) {
    link2="http://youraffiliatelink.com";
    adBanner2="image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==3) {
    link2="http://youraffiliatelink.com";
    adBanner2="image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==4) {
    link2="http://youraffiliatelink.com";
    adBanner2="image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==5) {
    link2="http://youraffiliatelink.com";
    adBanner2="image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==6) {
    link2="http://youraffiliatelink.com";
    adBanner2="image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==7) {
    link2="http://youraffiliatelink.com";
    adBanner2="image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==8) {
    link2="http://youraffiliatelink.com";
    adBanner2="image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==9) {
    link2="http://youraffiliatelink.com";
    adBanner2="image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    if (ad2==10) {
    link2="http://youraffiliatelink.com";
    adBanner2="image.jpg";
    width2="728";
    height2="90";
    alt2="Your Alt text";
    }
    document.write('<center><a href="' + link2 + '" target="_blank">');
    document.write('<img src="' + adBanner2 + '" width=' + width2 + ' height=' + height2 + ' border=0 alt="' + alt2 + '"></a>');
    document.write('</center>');
    where in the first line you change 10 to any number of banners that you want to rotate.

    Sure enough I am not an expert javascript programmer so maybe someone who is more experienced in javascript could explain to me why the complicated stuff at the top of the original script
    thanks!
     
    • Thanks Thanks x 1
    Last edited: Apr 11, 2016
  6. ChanzGrande

    ChanzGrande Jr. VIP Jr. VIP Premium Member

    Joined:
    Feb 16, 2008
    Messages:
    2,485
    Likes Received:
    1,153
    Occupation:
    Accountant
    Location:
    Northern Woods Counting Money
    That's certainly a great addition and observation Harvest Golem. I tend to just use openx to or even simpler PHP rotators, but this one works for those with limited ad inventory or placements and rotates quite linearly so can be good for split-testing banners.
     
  7. TheMossad

    TheMossad Registered Member

    Joined:
    Mar 4, 2016
    Messages:
    78
    Likes Received:
    13
    Where do i need to put this script? </head> or </body>

    I'm not an expert you in these kinda things you know
     
  8. AdvancedDevelopment

    AdvancedDevelopment BANNED BANNED

    Joined:
    Mar 23, 2016
    Messages:
    91
    Likes Received:
    28
    Put this script inside the HEAD tags

    Code:
    <head>
    <script> CODE HERE </script>  
    </head>
    
     
  9. goodperson

    goodperson Elite Member Premium Member

    Joined:
    Jan 3, 2015
    Messages:
    1,657
    Likes Received:
    222
    Location:
    www.niceaccount.com
    Home Page:
    I'm needing it, thanks