Need help w/rotating banner ads script to show up in multiple locations in same page

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by club777, May 30, 2013.

  1. club777

    club777 New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    What do i need to add to this script so i can use it multiple times in the same page without any conflicts?

    <script type="text/javascript">
    function initArray() { this.length = initArray.arguments.length;
    for (var i = 0; i < this.length; i++) {
    this = initArray.arguments;
    }
    }
    link = new initArray(
    "http://example.com/page1",
    "http://example.com/page2",
    "http://example.com/page3",
    "http://example.com/page4",
    "http://example.com/page5",
    "http://example.com/page6"
    );
    image = new initArray(
    "http://example.com/images/banner_1.jpg",
    "http://example.com/images/banner_2.jpg",
    "http://example.com/images/banner_3.jpg",
    "http://example.com/images/banner_4.jpg",
    "http://example.com/images/banner_5.jpg",
    "http://example.com/images/banner_6.jpg"
    );
    text = new initArray(
    "Example 1 Title",
    "Example 2 Title",
    "Example 3 Title",
    "Example 4 Title",
    "Example 5 Title",
    "Example 6 Title"
    );
    function getRandom(){
    var core = Math.floor(Math.random()*6); // amount of items in array
    displayBanner(core)
    }
    function displayBanner(theNum){
    var ranlink = link[theNum];
    var ranimage = image[theNum];
    var rantext = text[theNum];
    //document.write('<a href=\"' +ranlink+ '\" target=\"_blank\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>');
    document.getElementById('theImg').alt=rantext;
    document.getElementById('theImg').src=ranimage;
    document.getElementById('theLink').href=ranlink;
    }
    </script>
    <a href="#" target="_blank" id="theLink"><img src="" border="0" alt="" id="theImg"></a>
    <script type="text/javascript">
    getRandom();
    setInterval("getRandom()", 6000);
    </script>
     

Share This Page