Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help with my script. It works in Firefox but not IE

Status
Not open for further replies.

BWinder

IS-IT--Management
Jul 2, 2010
22
US
I am running this Rotating Javascript on my companies webpage. It works fine in Firefox but won't work in IE, can someone help me please?


<center>
<a id="rLink" style="color:white"><img id="rImage" width=198 height=150>
</a></center>

</body>


<SCRIPT LANGUAGE="JavaScript">

var interval = 5; // delay between rotating images (in seconds)
var random_display = 0; // 0 = no, 1 = yes
interval *= 1000;

var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem("/resource/resmgr/Ad_Banner/ad1.jpg", "image_list[image_index++] = new imageItem("/resource/resmgr/Ad_Banner/ad2.jpg", "image_list[image_index++] = new imageItem("/resource/resmgr/Ad_Banner/ad3.jpg", "image_list[image_index++] = new imageItem("/resource/resmgr/Ad_Banner/ad4.jpg", "image_list[image_index++] = new imageItem("/resource/resmgr/Ad_Banner/ad5.jpg", "image_list[image_index++] = new imageItem("/resource/resmgr/Ad_Banner/ad6.jpg", "image_list[image_index++] = new imageItem("/resource/resmgr/Ad_Banner/ad7.jpg", "image_list[image_index++] = new imageItem("/resource/resmgr/Ad_Banner/ad8.jpg", "
var number_of_image = image_list.length;

function imageItem(image_location, link) {
this.image_item = new Image();
this.image_item.src = image_location;
this.image_item.link = link;
}


function getNextImage() {
if (random_display) {
image_index = Math.floor(Math.random() * image_list.length);
}
else {
image_index = (image_index+1) % number_of_image;
}

var new_image = image_list[image_index];
return(new_image);
}


function rotateImage(rImage, link) {
var new_image = getNextImage();
document.getElementById('rImage').src = new_image.image_item.src;
document.getElementById('rLink').href = new_image.image_item.link;

setTimeout("rotateImage()", interval);

}

</script>
 
Should I have a { next to newplace = new Array(8); and then a } at the end of the links?
 
count=0 what is the picture? Start the array from index 0 rather than 1.
 
<IMG SRC="/resource/resmgr/Ad_Banner/ad1.jpg" WIDTH="198" HEIGHT="150" BORDER="0" id="bannerad"></a>

Do you mean change it here? I took out the ad1.jpg at the end of /resource/resmgr/Ad_Banner/ad1.jpg and it still didn't work. Is that what you meant?
 
[tt]<HTML><HEAD>
<TITLE>Rotating banners with links</TITLE>

<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -

if (document.images) {
ads = new Array(8);
ads[0] = "/resource/resmgr/Ad_Banner/ad1.jpg";
ads[1] = "/resource/resmgr/Ad_Banner/ad2.jpg";
ads[2] = "/resource/resmgr/Ad_Banner/ad3.jpg";
ads[3] = "/resource/resmgr/Ad_Banner/ad4.jpg";
ads[4] = "/resource/resmgr/Ad_Banner/ad5.jpg";
ads[5] = "/resource/resmgr/Ad_Banner/ad6.jpg";
ads[6] = "/resource/resmgr/Ad_Banner/ad7.jpg";
ads[7] = "/resource/resmgr/Ad_Banner/ad8.jpg";
}

newplace = new Array(8);
newplace[0] = "newplace[1] = "newplace[2] = "newplace[3] = "newplace[4] = "newplace[5] = "newplace[6] = "newplace[7] = "

var timer = null
var counter = 0

function banner() {
timer=setTimeout("banner()", 5000);
counter++;
if (counter >= 8)
counter = 0;
document.getElementById("bannerad").src = ads[counter]+'?'+(new Date()).getTime();
}

function gothere() {
counter2 = counter;
window.location.href = newplace[counter2];
}

// - End of JavaScript - -->
</SCRIPT>

</HEAD>
<BODY BGCOLOR="#FFFFFF" onload="banner()">

<a href="javascript:gothere()"><IMG SRC="/resource/resmgr/Ad_Banner/ad1.jpg" WIDTH="198" HEIGHT="150" BORDER="0" id="bannerad"></a>

</BODY>
</HTML>[/tt]
 
What is different on the one you pasted?
 
I still can't get this to rotate in IE. Might you have a script that I can use that will work in both?
 
I changed the array to start with 0 and still won't rotate. I am getting a headache with this stupid thing.
 
It's working now. Thank you so much for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top