faqts : Computers : Programming : Languages : JavaScript : Images

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

25 of 30 people (83%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Why does my onmouseover for IMGs not work with NN2/3/4 and IE3
I have noticed onMouseOut to undo onClick such that the object does not remain clicked.

Feb 9th, 2000 15:26
Martin Honnen, Smita Desai,


These browsers do not support 
  onmouseover
  onmouseout
handlers for the IMG element. 
With NN2/3/4 (and probably IE3 though someone needs to check that) you 
can wrap your IMG into a link e.g.
  <A HREF="#" 
     ONMOUSEOVER="your handler code here"
     ONMOUSEOUT="your handler code here"
     ONCLICK="return false;"
  ><IMG SRC="whatever.gif" BORDER="0"></A>
to use the onmouseover handler of the link.
If you do not script for NN2 inclusive but just NN3  then
  <A HREF="javascript: void 0" 
     ONMOUSEOVER="your handler code here"
     ONMOUSEOUT="your handler code here"
     ONCLICK="return false;"
  ><IMG SRC="whatever.gif" BORDER="0"></A>
is even more suitable to have a link not going anywhere but just 
providing the mouseover/out handler.  
Note that while NN2 (and probably IE3) provide the onmouseover/out 
handlers for the link they don't provide the
  document.images
object so the classical mouseover application of image swapping doesn't 
work at all with NN2 and IE3.
If you are only scripting for version 4 browsers you can use js to set 
up the event handlers for the IMG element. Though not documented that 
works with NN4 (at least on Win9x where I checked. Feedback about other 
platforms appreciated):
<IMG NAME="anImage" SRC="whatever.gif">
<SCRIPT>
document.anImage.onmouseover = 
  function (evt) {
    this.src = 'whatelse.gif';
  };
document.anImage.onmouseout = 
  function (evt) {
    this.src = 'whatever.gif';
  };
</SCRIPT>