Javascript Working in Firefox but not ie... where is the problem?
Hi all, I have some javascript I am using to rotate some banners based on time (Seconds)...
The script works perfectly in Firefox and th Java console gives me no error. But for some reason, I get a blank page in internet exporer (Vesion 6.0)... (No error message though)...where could my problem be?
My code is as follows:
================
<script TYPE="text/javascript" LANGUAGE="JavaScript">');
document.write('');}
if (navigator.appName == "Netscape"
&& parseInt(navigator.appVersion) >= 3) {
setTimeout('replace()',3000);}}
//--></script>
<script TYPE="text/javascript" LANGUAGE="JavaScript"></script>
Please enable JavaScript if you wish to see this image and link.
=============
I have tried everything...I think. Please help.
thanks
M.
JeevesBond posted this at 12:21 — 28th March 2006.
He has: 3,956 posts
Joined: Jun 2002
Ouch, you're going to kick yourself when you know what the problem was, try this:
<script type="text/javascript">
// <[CDATA[
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() {
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 + '">');
setTimeout('replace()',3000);
}
// ]]>
</script>
<script TYPE="text/javascript" LANGUAGE="JavaScript">
// <[CDATA[
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>
You were browser sniffing for Netscape, and only running the code if Netscape is the browser in use. IE (correctly for a change) ignored most of your code.
a Padded Cell our articles site!
JeevesBond posted this at 12:31 — 28th March 2006.
He has: 3,956 posts
Joined: Jun 2002
Oh and more importantly: That code also works in Opera. The bestest of all the browsers!
mizzy posted this at 12:32 — 28th March 2006.
They have: 47 posts
Joined: Jun 2001
You are right... I had to kick myself thee time for all the time wasted. trying to debug what was working. Man! Its almost like duuuhhhhh.
Thanks a lot.
JeevesBond posted this at 18:23 — 28th March 2006.
He has: 3,956 posts
Joined: Jun 2002
Heh, don't worry about it. I'm sure I've made worse mistakes.
Oh yeah, I was working on something for hours wondering why it was continuously failing. My colleague had gone home, and he was the one with the dev database server on his machine.
So after hours of messing around, all I had to do was turn his computer on. What a whazzock.
a Padded Cell our articles site!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.