homepage Welcome to WebmasterWorld Guest from 54.163.72.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
javascript not working in IE
javascipt not working in explorer
zzz477629




msg:4197301
 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);
if(Start>=a.length)
Start=0;
b.src = a[Start];
window.setTimeout("RotateImages("+whichHolder+","+(Start+1)+")",5000);
}

RotateImages(1,0);
RotateImages(2,0);

</script>

 

bhukkel




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

perhaps you need to start with:

<script type="text/javascript">

astupidname




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

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);
});

</script>

zzz477629




msg:4197629
 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.

zzz477629




msg:4198016
 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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved