MozillaZine

Simple JavaScript support??

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

Post Posted January 27th, 2007, 1:56 pm

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>

Dartman
Moderator

User avatar
 
Posts: 11991
Joined: February 9th, 2006, 9:43 pm

Post Posted January 27th, 2007, 2:01 pm

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 Posted January 27th, 2007, 3:58 pm

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 Posted February 5th, 2007, 9:04 am

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 Posted February 5th, 2007, 10:22 am

Not necessarily an error in the script. More like an error in the rest of the page.

Kelson

User avatar
 
Posts: 161
Joined: August 19th, 2005, 12:03 pm

Post Posted February 5th, 2007, 12:02 pm

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

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 1 guest