PDA

View Full Version : random .gif banner help



dynamically_not
03-15-2006, 06:24 PM
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:


<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....

jscheuer1
03-15-2006, 07:08 PM
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:


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

and:


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>");

dynamically_not
03-15-2006, 07:19 PM
I`ll give it a go thanks.

dynamically_not
03-15-2006, 08:01 PM
works a treat, thanks!