/    Sign up×
Community /Pin to ProfileBookmark

Image rotation problem in Mozilla

Hi All

Please can someone explain this to me and offer a solution?

I’m relatively new to Javascript but have got some excellent books and online resources. Wrote a script to handle banner rotation which works perfectly in IE but not in Mozilla (very strange). So I copied the script “Displaying a random image” from the book (Javascript for the worldwide web; [url]http://www.chalcedony.com/javascript3e/index.html?scripts/index.html[/url]) and the error still persists, only in Mozilla.

The error is this: Despite naming the <img> tags uniquely, and specifying “document.imgName.src=adImages[thisAd]” more than one image is changed. there is a cyclical pattern to this error too.

Here is the page source:

<html>
<head>
<title>Rotating Banner Problem</title>
<script type=”text/javascript” language=”Javascript”>
<!– Hide script from old browsers

adImages = new Array(“images/banner/one.gif”,”images/banner/two.gif”,”images/banner/three.gif”)
imgCt = adImages.length
firstTime = true

function rotate() {
if (document.images) {
if (firstTime) {
thisAd = Math.floor((Math.random() * imgCt))
firstTime = false
}
else {
thisAd++
if (thisAd == imgCt) {
thisAd = 0
}
}
document.Bthree.src=adImages[thisAd]
setTimeout(“rotate()”, 3 *
1000)
}
}

// End hiding script from old browsers –>
</script>
</head>
<body style=”background-color: rgb(171, 157, 110); margin-left: 0px; margin-top: 0px;” onload=”rotate()” marginheight=”0″ marginwidth=”0″>

<div id=”topBanner” style=”position: absolute; left:230px; top: 0px; height:100px; z-index: 99;”>
<img src=”images/banner/six.gif” width=”92″ height=”92″ name=”Bone” />
<img src=”images/banner/seven.gif” width=”92″ height=”92″ name=”Btwo” />
<img src=”images/banner/eight.gif” width=”92″ height=”92″ name=”Bthree” />
<img src=”images/banner/nine.gif” width=”92″ height=”92″ name=”Bfour” />
<img src=”images/banner/ten.gif” width=”92″ height=”92″ name=”Bfive” />
<img src=”images/banner/eleven.gif” width=”92″ height=”92″ name=”Bsix” />
<img src=”images/banner/twelve.gif” width=”92″ height=”92″ name=”Bseven” />
<img src=”images/banner/one.gif” width=”92″ height=”92″ name=”Beight” />
<img src=”images/banner/two.gif” width=”92″ height=”92″ name=”Bnine” />

</div>

</body>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisNov 08.2006 — Declare the var "thisAd" outside the function and see if that helps any.
Copy linkTweet thisAlerts:
@RamphiophisauthorNov 08.2006 — Thanx it does help a bit but not completely. Strangely, every once in a while it still changes another of thhe images not specified. But it is much less than before. Any ideas how to get rid of it completely?
×

Success!

Help @Ramphiophis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...