On Jun 22, 8:39 pm, VAXman- @SendSpamHere.O RG wrote:
I have code which is created from a content mamagement system. It places
some handlers on tags with in-line registration:
<tag... onmousedown="mo usedownHandler( this);" ...>
I want to modified the handler and access the event. Here's an example of
such (very contrived example):
fucntion mousedownHandle r(obj) {
if (!e) e = window.event;
As e is (most probably[1]) undefined, the test is always true. A
global variable e is created and its value set as a reference to the
result of evaluating the expression "window.eve nt".
In the IE event model, an event object is available as a property of
the window object. Safari partially supports this model, hence in the
above code e is given a reference to the event object.
Firefox follows the Netscape model for event handling where the event
object must be passed to the function, it isn't available as a global
property.
this.style.top = e.clientY +'px';
}
This works in Safari as it knows the event as e
No, it doesn't. See above.
and I can get it for M$IE
with the window.event.
Which is how Safari gets it too.
How do I go about accessing it in Firefox?
You must pass a reference to the event object when calling the
function.
BTW, I can't readily modify the CMS nor does the customer want to change
CMS.
Then, in polite terms, you're screwed. :-)
One solution is to call the handler using:
<... onmousedown="mo usedownHandler( event);" ...>
Then you can get the element using the event object:
function mousedownHandle r(evt) {
var tgt = evt.target || evt.srcElement;
// In some browsers tgt may be a #text node
if (tgt.nodeType == 3) tgt = tgt.parentNode;
...
}
But that requires modification of the CMS. You might try modifying
the inline handlers to pass the event object as an additional last
argument:
<... onmousedown="mo usedownHandler( this, event);" ...>
and use:
function mousedownHandle r(obj, evt) {
// evt is the event object in both models
// obj is the element that has the handler
}
So existing functions aren't affected, they'll just ignore the extra
parameter.
You can read about events here:
<URL:
http://www.quirksmode.org/js/introevents.html >
1. If you have created a global e somewhere else, e will be defined,
the test will evaluate to false and you won't get the current event
object.
--
Rob