Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

javascript not working in IE

javascipt not working in explorer



9:28 pm on Sep 6, 2010 (gmt 0)

hi, I'm very new to using javascript. I have a small bit I am using on my website and for some reason the swap image rotator script works in safari and firefox but will not work in internet explorer. I have no idea how to fix this. the script is as follows:

<script language="JavaScript">

var ImageArr1 = new Array("img1.jpg","img2.gif","img3.jpg");
var ImageHolder1 = document.getElementById('img1');

function RotateImages(whichHolder,Start)
var a = eval("ImageArr"+whichHolder);
var b = eval("ImageHolder"+whichHolder);
b.src = a[Start];




9:55 pm on Sep 6, 2010 (gmt 0)

perhaps you need to start with:

<script type="text/javascript">


5:25 am on Sep 7, 2010 (gmt 0)

5+ Year Member

Try it like this, note you should check the image paths in imageArr2:

<script type="text/javascript">

function addThisEvent(el, type, fn) {
var ename = type.replace(/^on/i,"");
if (el.attachEvent) { //IE
el.attachEvent("on"+ ename, function () { return fn.call(el, window.event)}); /*fixes IE's fudging of 'this' in attachEvent*/
} else if (el.addEventListener) { //Standard
el.addEventListener(ename, fn, false );
} else {
el["on"+ename] = fn;

function rotateImages(img, arr, start) {
if(start >= arr.length) {
start = 0;
img.src = arr[start];
window.setTimeout(function () {rotateImages(img, arr, ++start);}, 5000);

addThisEvent(window, 'load', function () {
var imageArr1 = ["img1.jpg", "img2.gif", "img3.jpg"],
imageHolder1 = document.getElementById('img1'),
imageArr2 = ["img4.jpg", "img3.gif", "img5.jpg"], //set the paths in this array to whatever yours should be
imageHolder2 = document.getElementById('img2');
rotateImages(imageHolder1, imageArr1, 0);
rotateImages(imageHolder2, imageArr2, 0);



12:23 pm on Sep 7, 2010 (gmt 0)

I used the exact code you posted (changing the images obv) and it still is not displayed at all in Internet Explorer. Still works in the other browsers though.


9:04 pm on Sep 7, 2010 (gmt 0)

aside from that....is there a way to get the images to pause on mouseover with that code you posted?

Featured Threads

Hot Threads This Week

Hot Threads This Month