Simple JavaScript support??

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
Post Reply
pronecracker
Posts: 2
Joined: January 27th, 2007, 1:38 pm

Simple JavaScript support??

Post by pronecracker »

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?

Code: Select all

<SCRIPT LANGUAGE="JavaScript">
<!--

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;
}

// -->
</SCRIPT>
<P><A HREF="#" onMouseOver="act()" onMouseOut="inact()">
<IMG SRC="advann.gif" HEIGHT="24" WIDTH="120"
     NAME="advan" BORDER="0" ALT="Netscent Advantages"></A></P>
User avatar
Dartman
Moderator
Posts: 11995
Joined: February 9th, 2006, 9:43 pm

Post by Dartman »

Moving to Web Development.
Alcohol and Calculus don't mix. Never drink and derive.
old np
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old np »

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!)
pronecracker
Posts: 2
Joined: January 27th, 2007, 1:38 pm

Post by pronecracker »

So it's an error in the script? Allright, don't know why it did work in IE but you're right the first example does.
old np
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old np »

Not necessarily an error in the script. More like an error in the rest of the page.
User avatar
Kelson
Posts: 161
Joined: August 19th, 2005, 12:03 pm
Contact:

Post by Kelson »

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.
Can Firefox users and Opera fans agree on anything? The Alternative Browser Alliance
Post Reply