L
Lasse Reichstein Nielsen
Ekkehard Morgenstern said:Now, tell me how to get DOM 2 event listeners to work for Netscape/Mozilla
and Opera! ;-)
By following the specification?
With my method,
var listener = new Array();
listener.handleEvent = Code;
element.addEventListener( eventtype, listener, false );
it works on Netscape/Mozilla, whereas
Surpricing.
element.addEventListener( eventtype, Code, false );
doesn't.
Even more surpricing, as that is the correct way to do it.
Code is guaranteed to refer to a function of the form:
function Code( Event ) {
Then you are doing something wrong. It works for me.
---
var element = document.body;
var eventtype = "click";
var Code = function (Event) { alert(Event.target.tagName); };
element.addEventListener(eventtype,Code,false);
---
Works in both Mozilla and Opera 7.
Neither method works with Opera.
You must be doing something else wrong.
What I need is an algorithm that supports any of the HTML event types,
like "load", "mouseover" etc.
Qur? You need an *algorithm* that *supports* event types? What should
the algorithm DO?
I need them on window or at least document objects as well.
As it has beens tated, Opera only has addEventListener on DOM nodes,
and not on the window object. You have to treat the objects differently.
Or should I replace calls supplying window or document as element
with using the body-tag element?
Probably not. Just don't use the same method for all host objects.
It's not hard to test whether addEventListener exists.
/L