guruunlimited
12-04-2003, 05:07 PM
Could anyone tell me..if I have banner rotater code...how can I make sure that the URL that the new window opens to is of fixed length.
Find below the code I am working on.
What I want to happen is when the banner rotates..and the image is displayed..user can click on the image(url) and get the url/image in a new window which is sized (say 250 x 350)..
Please help...urgent school project...
=================
Code Begins
=================
<!-- Banner Rotater Code Begins -->
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function banner(imgSource,url,alt,chance) {
this.imgSource = imgSource;
this.url = url;
this.alt = alt;
this.chance = chance;
}
function dispBanner() {
with (this) document.write("<A HREF=" + url + "><IMG SRC='" + imgSource + "' WIDTH=170 HEIGHT=150 BORDER=0 ALT='" + alt + "'></A>");
}
banner.prototype.dispBanner = dispBanner;
banners = new Array();
banners[0] = new banner("wgallery/Angel_2003.jpg",
"http://www.linktest.net",
"rlinktest.net,picture-1",
10);
banners[1] = new banner("wgallery/Angry_Planet.jpg",
"http://www.linktestn.net",
"rlinktestnon.net,picture-2",
30);
banners[2] = new banner("wgallery/dragon.jpg",
"http://www.rlinktest.net",
"rlinktest.net,picture-3",
20);
banners[3] = new banner("wgallery/lambor.jpg",
"http://www.rlinktest.net",
"rlinktestn.net,picture-4",
20);
banners[4] = new banner("wgallery/nature.jpg",
"http://www.linktestn.net",
"rlinktestn.net,picture-5",
20);
banners[5] = new banner("wgallery/porsche911.jpg",
"http://www.linktestn.net",
"ralinktest.net,copyright",
20);
///////////////////////////////////////////////////
// banners[x] = new banner(<banner source image>, // <url to link to when the banner is clicked>, // <alt> // <the chance this banner has in which to be randomly selected>);
// To increase the chance of a banner being randomly selected, increase it's corresponding // 'chance' property relative to the other banners.
///////////////////////////////////////////////////
sum_of_all_chances = 0;
for (i = 0; i < banners.length; i++) {
sum_of_all_chances += banners[i].chance;
}
function randomBanner() {
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].imgSource + "' WIDTH=150 HEIGHT=100 BORDER=0 ALT='" + banners[i].alt + "'></A>");
return banners[i];
break;
}
}
}
// End -->
</script>=================
Code Ends
=================
Find below the code I am working on.
What I want to happen is when the banner rotates..and the image is displayed..user can click on the image(url) and get the url/image in a new window which is sized (say 250 x 350)..
Please help...urgent school project...
=================
Code Begins
=================
<!-- Banner Rotater Code Begins -->
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function banner(imgSource,url,alt,chance) {
this.imgSource = imgSource;
this.url = url;
this.alt = alt;
this.chance = chance;
}
function dispBanner() {
with (this) document.write("<A HREF=" + url + "><IMG SRC='" + imgSource + "' WIDTH=170 HEIGHT=150 BORDER=0 ALT='" + alt + "'></A>");
}
banner.prototype.dispBanner = dispBanner;
banners = new Array();
banners[0] = new banner("wgallery/Angel_2003.jpg",
"http://www.linktest.net",
"rlinktest.net,picture-1",
10);
banners[1] = new banner("wgallery/Angry_Planet.jpg",
"http://www.linktestn.net",
"rlinktestnon.net,picture-2",
30);
banners[2] = new banner("wgallery/dragon.jpg",
"http://www.rlinktest.net",
"rlinktest.net,picture-3",
20);
banners[3] = new banner("wgallery/lambor.jpg",
"http://www.rlinktest.net",
"rlinktestn.net,picture-4",
20);
banners[4] = new banner("wgallery/nature.jpg",
"http://www.linktestn.net",
"rlinktestn.net,picture-5",
20);
banners[5] = new banner("wgallery/porsche911.jpg",
"http://www.linktestn.net",
"ralinktest.net,copyright",
20);
///////////////////////////////////////////////////
// banners[x] = new banner(<banner source image>, // <url to link to when the banner is clicked>, // <alt> // <the chance this banner has in which to be randomly selected>);
// To increase the chance of a banner being randomly selected, increase it's corresponding // 'chance' property relative to the other banners.
///////////////////////////////////////////////////
sum_of_all_chances = 0;
for (i = 0; i < banners.length; i++) {
sum_of_all_chances += banners[i].chance;
}
function randomBanner() {
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].imgSource + "' WIDTH=150 HEIGHT=100 BORDER=0 ALT='" + banners[i].alt + "'></A>");
return banners[i];
break;
}
}
}
// End -->
</script>=================
Code Ends
=================