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>
 
>but won't work in IE
In what sense? If it does not rotate, you can try this.
>document.getElementById('rImage').src = new_image.image_item.src;
[tt]document.getElementById('rImage').src = new_image.image_item.src[blue]+'?'+(new Date()).getTime()[/blue];[/tt]
 
All I get is a broken link in IE, no images at all.
 
If there is no image at all in ie, but fine in ff, that effectively asserts that ie cannot read the absolute path. I cannot help. I believe the ability of reading an absolute path to find the resource is not an issue related to cross-browser compatibility. I addressed only the issue of rotation.
 
I am now using this script which I get a image with link but no rotation. I am only getting 1 image in IE but still works fine in Firefox.

<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 >= 3)
counter = 0;
document.bannerad.src = ads[counter];
}

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" NAME="bannerad"></a>

</BODY>
</HTML>
 
In that case, you can try my suggestion. It would be something like this.
>document.bannerad.src = ads[counter];
[tt]document.bannerad.src = ads[counter][blue]+'?'+(new Date()).getTime()[/blue];

ps: I had not read in full the new version. The version in the op should work though. So, I cannot say for sure why you can't get it in the op version.
 
With the change you suggested

<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 >= 3)
counter = 0;
document.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" NAME="bannerad"></a>

</BODY>
</HTML>


it is still not rotating in IE. Just shows 1 image with link.
 
Why do you abandoned the id and replaced it by name? Even if you use name for the img tag, it is not accessed by document.bannerad! Return to use id and access it by document.getElementById() method.
 
So it will look like this?

<HTML><HEAD>
<TITLE>Rotating banners with links</TITLE>

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

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

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

var timer = null
var counter = 0

function banner() {
timer=setTimeout("banner()", 5000);
counter++;
if (counter >= 8)
counter = 0;
document.getElementById() = 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" NAME="bannerad"></a>

</BODY>
</HTML>
 
>document.getElementById() = ads[counter]+'?'+(new Date()).getTime();
[tt]document.getElementById([red]"bannerad"[/red]) = ads[counter]+'?'+(new Date()).getTime();[/tt]

><IMG SRC="/resource/resmgr/Ad_Banner/ad1.jpg" WIDTH="198" HEIGHT="150" BORDER="0" NAME="bannerad">
[tt]<IMG SRC="/resource/resmgr/Ad_Banner/ad1.jpg" WIDTH="198" HEIGHT="150" BORDER="0" [red]id[/red]="bannerad">[/tt]
 
Now it is not rotating in either Firefox or IE, just the one image with the link.

<HTML><HEAD>
<TITLE>Rotating banners with links</TITLE>

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

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

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

var timer = null
var counter = 0

function banner() {
timer=setTimeout("banner()", 5000);
counter++;
if (counter >= 8)
counter = 0;
document.getElementById("bannerad") = 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>
 
My bad. But the script makes me sick.
[tt]
document.getElementById("bannerad")[red].src[/red] = ads[counter]+'?'+(new Date()).getTime();
[/tt]
 
It's making me sick as well. I am new to JavaScript and it's been kicking my butt trying to get this to work. I appreciate all your help. I will give that a try.
 
It's rotating in Firefox again, but is still not rotating in IE, just the image.

<HTML><HEAD>
<TITLE>Rotating banners with links</TITLE>

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

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

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

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>
 
I'm sorry, what do you mean? Like I said, I am really new to JavaScript and this is all my first attempt at this.
 
Where is its curly bracket '}' at the end?
 
Like this?

<HTML><HEAD>
<TITLE>Rotating banners with links</TITLE>

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

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

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

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>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top