Link to home
Start Free TrialLog in
Avatar of muttley1
muttley1

asked on

Image Map

Hi There,
This is probably very simple but only when you know how!

The following code works perfectly with IE, but doesn't work with Netscape.

Why??

  <SCRIPT Language="JavaScript">
<!--
start = new Image()
start.src = "images/starters.gif"
main = new Image()
main.src= "images/maincourse.gif"
dessert = new Image()
dessert.src = "images/dessert.gif"

function menuStart() {
document.menu.src = start.src;
}

function menuMain() {
document.menu.src = main.src;
}

function menuDessert() {
document.menu.src = dessert.src;
}
-->
  </SCRIPT>
</HEAD>
<BODY  BGCOLOR="#b99d80">

<map name="menumap">
<area shape="rect" coords="11,16,165,50" href="JavaScript: menuStart()">
<area shape="rect" coords="166,15,365,53" href="JavaScript: menuMain()">
<area shape="rect" coords="366,18,514,49" href="JavaScript: menuDessert()">
</map>

<P><CENTER><IMG SRC="images/starters.gif" NAME="menu" WIDTH="530" HEIGHT="1000"
ALIGN="BOTTOM" BORDER="0" NATURALSIZEFLAG="3" USEMAP="#menumap"></CENTER>

</BODY>
</HTML>
Avatar of knightEknight
knightEknight
Flag of United States of America image

For NS you must refer to the images array (should also work in IE):

function menuStart() {
    document.images['menu'].src = start.src;
}

function menuMain() {
    document.images['menu'].src = main.src;
}

function menuDessert() {
    document.images['menu'].src = dessert.src;
}
Avatar of muttley1
muttley1

ASKER

Thanks for the rapid response!
I tried using the method you suggested.
Again it worked fine with IE but it didn't with Netscape.
On thing I did notice though is the cursor changes on mousing over the hotspots. It just doesn't run the function.

It can't be that far away!
Hmm, how about this:

<area shape="rect" coords="11,16,165,50" onClick="menuStart()">
<area shape="rect" coords="166,15,365,53" onClick="menuMain()">
<area shape="rect" coords="366,18,514,49" onClick="menuDessert()">
Adjusted points to 150
Nope!
Again works great with IE but not Netscape.
Also, the cursor doesn't change moving over the hotspots like last time.

I'm pushing it up to 150 points!

Help!!
Ah, that's because I left out the href.  I admit, I'm guessing here because I can't test this:

<area shape="rect" coords="11,16,165,50" href="#"  onClick="menuStart();return(false);">
<area shape="rect" coords="166,15,365,53" href="#" onClick="menuMain();return(false);">
<area shape="rect" coords="366,18,514,49" href="#" onClick="menuDessert();return(false);">
... or better than  "#"  is  "javascript:;"
Thanks again but.....

It works fine with IE, not with Netscape.
(I'm beginning to sound like a stuck record!)
Now the cursor changes while mousing over the hotpoints but onClick doesn't run the functions.
I just get a little egg timer for a few seconds. No JavaScript errors either!

Any other ideas?
ASKER CERTIFIED SOLUTION
Avatar of us111
us111
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank's us111,
Problem solved!
I won't forget that one in a hurry.
thx for you 150 points
you're welcome :-)
I wouldn't have seen that in a million years  :)

But I am wondering if NS works with the functions as posted above:

function menuDessert() {
  document.menu.src = dessert.src;
}

.... or did you have to do this?:

function menuDessert() {
  document.images['menu'].src = dessert.src;
}
It works with both.
I use the function:

function menuDessert() {
                 document.menu.src = dessert.src;
               }
 often with mouse overs to change images.

I can't believe that // could make such a difference!

Thanks for trying anyway. I'm sure this isn't the last you've heard of me here. It's a great site.