![]() |
Why doesn't this work in Firefox?
Hi,
I'm new to all this stuff so please go easy on me if this is a simple error :-) This code is to swap two images on a page by use of a timer. It works in IE but not in Firefox. Can someone please point out what's wrong? Thanks, Ade <html> <head> <script language="javascript" type="text/javascript"> var Timer; // = setTimeout("swap()",1000); var iPic; var aPics=new Array(); iPic=0; aPics[0]="img1.bmp"; aPics[1]="img2.bmp"; function swap() { if (iPic == 1) iPic=0; else iPic=1; document.all.myImage.src = aPics[iPic]; Timer = setTimeout("swap()",1000); } </script> </head> <body onload=swap();> <img name="myImage" src="img1.bmp"></img> </body> </html> |
Re: Why doesn't this work in Firefox?
"Ade" <adrian.nospam.birkett@blueyonder.co.uk> wrote in message news:GMOaj.33318$036.15455@fe1.news.blueyonder.co. uk... > Hi, > > I'm new to all this stuff so please go easy on me if this is a simple > error :-) > > This code is to swap two images on a page by use of a timer. It works in > IE but not in Firefox. Can someone please point out what's wrong? Turn on the errorconsole, or install firebug, and look at the error FF will give you. -- Richard. |
Re: Why doesn't this work in Firefox?
"rf" <rf@invalid.com> wrote in message news:VSOaj.26161$CN4.12539@news-server.bigpond.net.au... > > "Ade" <adrian.nospam.birkett@blueyonder.co.uk> wrote in message > news:GMOaj.33318$036.15455@fe1.news.blueyonder.co. uk... >> Hi, >> >> I'm new to all this stuff so please go easy on me if this is a simple >> error :-) >> >> This code is to swap two images on a page by use of a timer. It works in >> IE but not in Firefox. Can someone please point out what's wrong? > > Turn on the errorconsole, or install firebug, and look at the error FF > will give you. > > -- > Richard. > Richard, Thanks for that, I didn't know that the error console was there. I'll try a different method. Ade |
Re: Why doesn't this work in Firefox?
Ade wrote:
> "rf" <rf@invalid.com> wrote in message > news:VSOaj.26161$CN4.12539@news-server.bigpond.net.au... >> "Ade" <adrian.nospam.birkett@blueyonder.co.uk> wrote in message >> news:GMOaj.33318$036.15455@fe1.news.blueyonder.co. uk... >>> Hi, >>> >>> I'm new to all this stuff so please go easy on me if this is a simple >>> error :-) >>> >>> This code is to swap two images on a page by use of a timer. It works in >>> IE but not in Firefox. Can someone please point out what's wrong? >> Turn on the errorconsole, or install firebug, and look at the error FF >> will give you. >> >> -- >> Richard. >> > Richard, > > Thanks for that, I didn't know that the error console was there. I'll try a > different method. > It will tell you to use document.getElementByID("myImage") and to set an id rather than a name for the tagged element. Among other things, perhaps. |
Re: Why doesn't this work in Firefox?
Ade wrote:
> This code is to swap two images on a page by use of a timer. It works in IE > but not in Firefox. Can someone please point out what's wrong? > [...] > <html> > <head> Your markup is not Valid. You should apply http://validator.w3.org/ and make the necessary modifications if you want to have at least a realistic chance of interoperable code. Note that despite the Validator recommending XHTML due to W3C politics if the DOCTYPE declaration was omitted, you should declare and validate against HTML 4.01 (preferably Strict) instead as XHTML is not yet universally supported on the Web and probably not required in your case. > <script language="javascript" type="text/javascript"> The `language' attribute is deprecated. It is syntactically invalid in HTML 4.01 Strict, XHTML 1.0 Strict and XHTML 1.1. > var Timer; // = setTimeout("swap()",1000); `Timer' does not designate a constructor, so it should be `timer'. > var iPic; It does not make sense here to declare the variable here and initialize it elsewhere. var iPic = 0; > var aPics=new Array(); > > iPic=0; > aPics[0]="img1.bmp"; > aPics[1]="img2.bmp"; You might want to consider var aPics = new Array("img1.bmp", "img2.bmp"); > function swap() > { if (iPic == 1) > iPic=0; > else > iPic=1; Storing the toggle status in a boolean variable might be better and easier to program: var iPic = false; // ... iPic = !iPic; // ... +iPic > document.all.myImage.src = aPics[iPic]; Although recent Firefox version support `document.all' to a certain extent, that is an MSHTML-proprietary feature. Instead, use document.images["myImage"].src = aPics[iPic]; which is both standards-compliant and backwards-compatible, and therefore most interoperable. > Timer = setTimeout("swap()",1000); setTimeout() is a host-defined method of the host object referred to by `window' and should be called so: var timer = window.setTimeout("swap()", 1000); Note that since JavaScript 1.2 (in Netscape Navigator 4.0) the method takes a Function object reference as first argument, so you may as well write var timer = window.setTimeout(swap, 1000); You should also note that this fast an image swapping, like blinking text, introduces an accessibility issue. The average simple reaction time of humans is about one third of a second if the event is expected, and one second if it is unexpected -- and you should consider that disabled and aged people use the Web in greater proportions than other groups of people. > [...] HTH PointedEars -- realism: HTML 4.01 Strict evangelism: XHTML 1.0 Strict madness: XHTML 1.1 as application/xhtml+xml -- Bjoern Hoehrmann |
| All times are GMT. The time now is 11:49 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.