Step four - Change images on mouse events
A mouse over and mouse out event in a link can also be very useful when
the link is around a image. This would indicate to the script whether the mouse is on
a image or not. To show that to the user as well you could change the
image. So the user knows where he or she is about to click on.
When you point at the image it will change color, because it loads different images
on mouse over and mouse out. link around the image looks as follows:
<img src="pix/2.gif" height=52 width=53
As you can see for both events the same script was called.
Again the difference is only that the function is called with a
different value. In the script the passed value is hold in the variable
image_url which is then assign to the source of the image to change it.
if (! (document.images)) return;
Before assign the value to be the new source for the image I do check
whether the browser even knows image objects.
If it does not know how
to handle images and I would assign the value it would produce an error
message. This would happen for example in Netscape 2 and Explorer 3. In these cases I rather return to do nothing.
it is also possible to read the source of an image
but this returns the complete URL although you might only be
interested in the last bit which is the actual filename.
if (filename=="greendot.gif") return true
sp you look for the total length of the URL and copy then the number of
characters you need off from the end the URL. This can then be compared
in an if test.