Forum Moderators: open
Inherited a .js file below that rotates banners, and users are able to click on a link to open the sponsor link in a new window.
I believe it was supposed to work in Netscape an IE, but of course, the banners do not rotate in Netscape. Only the first image banner displays?
banner.js file:
var imgs1 = new Array("image1.jpg","image2.gif","etc...")
var lnks1 = new Array("link1","link2", "etc....")
var alt1 = new Array("image1text","image2text","etc..")
var currentAd1 = 0
var imgCt1 = 3
function cycle1() {
currentAd1++
if (currentAd1 == imgCt1) {
currentAd1 = 0
}
document.adBanner1.src=imgs1[currentAd1]
document.adBanner1.alt=alt1[currentAd1]
adLink1.href=lnks1[currentAd1]
setTimeout("cycle1()",10 * 1000)
}
For the imgs1, I am using external image files, as with the links in the lnks1 variable. The imgCt1 is how many images you choose to include and should match the number of images in imgs1. Works great in IE....
This code is place in the appropriate spot within the HTML doc:
<script type="text/javascript" language="JavaScript" src="banner.js">
</script>
<a href="any link" name="adLink1" target="_blank"><img alt="" src="whatever image" name="adBanner1" border="0" width="468" height="60"></a>
<script type="text/javascript" language="JavaScript">
cycle1()
</script>
Sure it could be an easy answer, but I just don't have the experience w/ javascript and how it behaves in different browsers.
Thanks.....
Hi there..
Here is the free example of the banner rotator, you may take a look...
I using external links and images for the banners since they are part of an ad campaign....
So here is what I need:
1) A rotator that will rotate banners (468x60) on a time you set (not one banner per refresh or going to another page on the site);
2) Support external images and URL links;
3) Supported by IE and Netscape
4) WISH LIST - Keeps stats on clicks, etc. (not necessary for now).
The one I am using above does what I need (except #4), but the banners will not rotate in Netscape 4.78 and up. The first banner just stays. IE works great...
You can see here: www.tcustomgolf.com
then look near the bottom of any page.
Thanks to all....
************
var imgs1 = new Array("image1.jpg","image2.gif","etc...")
var lnks1 = new Array("link1","link2", "etc....")
var alt1 = new Array("image1text","image2text","etc..")
var currentAd1 = 0
var imgCt1 = 3
function cycle1() {
currentAd1++
if (currentAd1 == imgCt1) {
currentAd1 = 0
}
document.adBanner1.src=imgs1[currentAd1]
document.adBanner1.alt=alt1[currentAd1]
adLink1.href=lnks1[currentAd1]
setTimeout("cycle1()",10 * 1000)
}
************
May change
"var imgs1 = new Array("image1.jpg","image2.gif","etc...")"
-->
var imgs1 = new Array("images/image1.jpg","images/image2.gif","images/image3.gif")
May change "var imgCt1 = 3"
--> var imgCt1 = imgs1.length
From the funtion cycle1()...
-->
function cycle1(){
if (document.images){
if document.adBanner1.complete){
currentAd1++
if (currentAd1 == imgCt1) {
currentAd1 = 0
}
document.adBanner1.src=imgs1[currentAd1]
}
setTimeout("cycle1()", 3 * 1000)
}
}
// add the new location function for the links
function newLocation(){
document.location.href = "http://www." +
alt1[currentAd1]
}
From the Page...
-->
<body onload="cycle1()">
anywhere if you like the banners go...
<p>
<center>
<a href="javascript:newLocation()"><img src="images/images1.jpg" width="..." height="..." name="adBanner1" border="0" alt="..."></a>
</center>
#######
.... hope this help... a bit long but if works then end of the year and welcome the New Year 2004 :)~
webkid
p.s. Also check the book from the website:
[javascriptworld.com...]
chapter3 the example: [javascriptworld.com...]
// add the new location function for the links
function newLocation(){
document.location.href = "http://www." +
alt1[currentAd1]
}
Putting target="_blank" after the call in my html page doesn't seem to work.
Took some of your code, and the code from the link you gave me and besides the above, it works well..
Thanks again...
function newLocation() {
//document.location.href = "http://www." + adURL[thisAd]
window.open("http://www." + adURL[thisAd],"my_new_window","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes, width=400, height=400")
}
***********
Use window.open, no need document.location.href...
It works just fine :)
HTP and Happy 2004
webkid