We help IT Professionals succeed at work.

Javascript Works in Firefox but not in IE

mmofya
mmofya asked
on
Medium Priority
279 Views
Last Modified: 2008-02-01
Hi I havea banner rotator script which is working perfectly in Firefox but for some reason, it is not working in IE (v 6). All I get is a blank page with no error message. What could the problem be?
My code isas follows:
====================

<script TYPE="text/javascript" LANGUAGE="JavaScript"><!--
function Href(dest,image,text) {
this.dest = dest; this.image = image; this.text = text; }

function setHref(dest,image,text) {
myHref[hrefItems++] = new Href(dest,image,text); }

function replace() {
var now = new Date();
random = now.getSeconds()%hrefItems;
if (random == lastrandom) {
if (random == hrefItems-1) random--; else random++; }
document.banner.src = myHref[random].image;
document.links[0].href = myHref[random].dest;
setTimeout('replace()',3000);
lastrandom = random; }
function Test() {
if (navigator.appName == "Netscape") {
var now = new Date();
random = now.getSeconds()%hrefItems; lastrandom = random;
document.write('<A HREF="' + myHref[random].dest + '">');
document.write('<IMG NAME="banner" WIDTH=468 HEIGHT=60 ');
document.write('BORDER=0 ALT="Caption for image here" ');
document.write('SRC="' + myHref[random].image + '">');}
if (navigator.appName == "Netscape"
&& parseInt(navigator.appVersion) >= 3) {
setTimeout('replace()',3000);}}
//--></script>


<script TYPE="text/javascript" LANGUAGE="JavaScript"><!--
var random = 0;
var lastrandom = -1;
var hrefItems = 0;
var myHref = new Array();
setHref('http://www.website1.com','banner1.gif','alttag1');
setHref('http://www.website2.com','banner2.gif','alttag2');
setHref('http://www.website3.com','banner3.gif','alttag3');
Test();
//--></script>
<noscript>Please enable JavaScript if you wish to see this image and link.</noscript>

=================
Thanks in advance.
M.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004

Commented:
In your Test() function, you seem to have:

    if (navigator.appName == "Netscape") {

Which surely will stop Netscape working?
CERTIFIED EXPERT
Top Expert 2004
Commented:
>> Which surely will stop Netscape working?

I meant:

Which surely will stop IE from doing anything?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Wow...I wonder how I missed that.
Thanks
CERTIFIED EXPERT
Top Expert 2004

Commented:
Glad I could help!  Sometimes a second pair of eyes is all you need :-)

Good luck with it!

Tim
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.