Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get the event properties from an onMouseOver 1

Status
Not open for further replies.

RobBroekhuis

Technical User
Oct 15, 2001
1,971
US
Javascript event handlers get passed an event object which has useful properties - for example the mouse location. I can't figure out how to access this event object when the event is called from an onMouseOver="...." directive in an HTML element. What I tried, and didn't work, was:

<img src=&quot;...&quot; onMouseOver=&quot;DoEvent(event,'other arguments');&quot;>

<script>
function DoEvent(e,OtherArgumentList) {
alert(e.pageX);
}
</script>

How should I modify it?


Rob
[flowerface]
 
Rob...

pageX and pageY are Netscape only events. You would get the same thing in IE using offsetX and offsetY.

The following replacement line works for me using IE:

Code:
alert('x=' + e.offsetX + ' y=' + e.offsetY);

Regards,
Jeff
 
Thanks Jeff,
I figured out that simply &quot;x&quot; and &quot;y&quot; work as well. I guess I'm in need of a good cross-browser object reference.


Rob
[flowerface]
 
IE and NS use different means of getting Event objects to Event handlers. IE uses
Code:
window.event
, NS uses a function argument. A couple of solutions --
Code:
function doEvent(e) {
  if (document.all) { var e = window.event; }
  alert(e.pageX);
}
or
Code:
function doEvent(e) {
  e = (e) ? e : ((event) ? event : null);
  alert(e.pageX);
}
work most of the time. Opera can test positive for
Code:
document.all
depending on a parameter setting. Not sure how NS treats additional function arguments since the Event object is passed as argument.

Good luck.

 
Wray,
I use IE, and was successful passing the event as a function parameter (as in my initial post - the only thing wrong was trying to access the pageX property, which is undefined in IE). I just need to go get Netscape loaded on my PC, so I can test the performance for myself.


Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top