Look at this, it's a simple piece of HTML and JavaScript which creates a rollover button. It comes from this tutorial: http://www.webreference.com/js/column1/create.html# It works in IE and maybe other browsers, but not in Firefox. What can I do about this?
if (document.images) { var advanoff = new Image(); // for the inactive image advanoff.src = "advann.gif"; var advanon = new Image(); // for the active image advanon.src = "advana.gif"; }
function act() { if (document.images) document.images.advan.src = advanon.src; }
function inact() { if (document.images) document.images.advan.src = advanoff.src; }
The site defined multiple images with a name of "advan" - not only the one that's supposed to work but the sample images near the start of the article. If you hover over the image on the bottom, you can see the first sample image shows the effect (doh!)
The script looks for an image by name. Technically, no two images should have the same name. There's no specified way for a browser to deal with that situation. It looks like Firefox picks the first one, and IE picks the last one. It just happens that they wanted the last one, so IE's blind guess worked better for them than Firefox's blind guess.
So the script itself is fine, but the example is broken.
mozillaZine is an independent Mozilla community and advocacy site. We're not affiliated or endorsed by the Mozilla Corporation but we love them just the same.