Results 1 to 4 of 4

Thread: random .gif banner help

  1. #1
    Join Date
    Mar 2006
    Location
    Poison City, Africa
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default random .gif banner help

    greetings all,
    some help with this script would be appreciated;

    Its a script that allows the rotation of banners on a webpage, .gif banners in my case, inserted into a table in an Iframe. This is a section of the code:

    Code:
    <SCRIPT LANGUAGE="javascript">
    <!-- 
    function banner(img_source,url,alt,chance) {
       this.img_source = img_source;
       this.url = url;
       this.alt = alt;
       this.chance = chance;
    }
    function display() {
       with (this) document.write("<A HREF=" + url + "><IMG SRC='" + img_source + "' WIDTH=460 HEIGHT=115 BORDER=0 ALT='" + alt + "'></A>");
    }
    banner.prototype.display = display;
    banners = new Array();
    banners[0] = new banner("files/banner/0.gif",
                            "http://mysite/index.htm",
                            "",
    sum_of_all_chances = 0;
    for (i = 0; i < banners.length; i++) {
       sum_of_all_chances += banners[i].chance;
    }
    function display_banner() {
       chance_limit = 0;
       randomly_selected_chance = Math.round((sum_of_all_chances - 1) * Math.random()) + 1;
       for (i = 0; i < banners.length; i++) {
          chance_limit += banners[i].chance;
          if (randomly_selected_chance <= chance_limit) {
             document.write("<A HREF=" + banners[i].url + "><IMG SRC='" + banners[i].img_source + "' WIDTH=460 HEIGHT=115 BORDER=0 ALT='" + banners[i].alt + "'></A>");
             return banners[i];
             break;
          }
       }
    }
    //-->
    </SCRIPT>
    My question is: how would i have the link open in the _parent (same window) when clicking the banner. Hope i make sense....

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Unless you've put this in a frame, it already will be in the same window, otherwise it will be in the frame that the banner is in. Without testing, if it is in a frame, adding target='_top' to the two <a href tags should do:

    Code:
       with (this) document.write("<A HREF=" + url + " target='_top'><IMG SRC='" + img_source + "' WIDTH=460 HEIGHT=115 BORDER=0 ALT='" + alt + "'></A>");
    and:

    Code:
          if (randomly_selected_chance <= chance_limit) {
             document.write("<A HREF=" + banners[i].url + " target='_top'><IMG SRC='" + banners[i].img_source + "' WIDTH=460 HEIGHT=115 BORDER=0 ALT='" + banners[i].alt + "'></A>");
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2006
    Location
    Poison City, Africa
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I`ll give it a go thanks.

  4. #4
    Join Date
    Mar 2006
    Location
    Poison City, Africa
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    works a treat, thanks!

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
  •