On Thu, 26 Feb 2004 21:34:33 +0100, Lasse Reichstein Nielsen
<lrn@hotpop.com> wrote:
[color=blue]
> Michael Winter <M.Winter@blueyonder.co.invalid> writes:
>[color=green]
>> The problem is that IE, unlike most other browsers, doesn't pass an
>> event object to event listeners.[/color]
>
> Actually it does when you attech the listener with attachEvent.[/color]
It does? Well I'll be...
I assumed that as it doesn't when you use the event properties, it
wouldn't with attachEvent - a sensible connection, I thought.
I wonder why the differences occur. Could it be because attachEvent allows
multiple, concurrent listeners?
[color=blue]
> Try this.
> document.body.attachEvent("onclick",
> function(evt){alert(evt.srcElement.tagName);});
> in IE 5+ (couldn't get IE 4 to work well enough to test it there).[/color]
According the MS' DHTML reference, attachEvent was implemented in IE 5. IE
4 will still depend on assignment to the event properties. The OP's code
should probably be extended to:
if( newbutton.addEventListener ) {
newbutton.addEventListener('click',removeline,fals e);
} else if( newbutton.attachEvent ) {
newbutton.attachEvent('onclick',removeline);
} else {
newbutton.onclick = removeline;
}
if support for earlier browsers is required.
[color=blue]
> Now that attachEvent has started to look usefull, it's time to mention
> the shortcomming: The value of "this" when the handler is called is
> the global object, not the object that the handler is attached to
> (also unlike assigning to onclick, and unlike how other browsers
> treat addEventListener - even if it is not part of the DOM spec.).[/color]
That is quite a shortcoming. I realise that one can simply use
event.srcElement, but this is so much more convenient. Is it mentioned
anywhere in the references, or something that you know through experience?
Mike
[OT]
I always wanted to know why MS even decided to use a single, global event
object. Do browsers use a threaded model to process events, rather than a
queue? Is there any advantage - not necessarily speed, but responsiveness
perhaps - after weighing in the added overhead? If so, IE makes that very
difficult as more development effort would be required in order to make
sure that an event read the correct data.
[More OT nonsense]
I like this quote from the attachEvent method description:
"If you attach multiple functions to the same event on the same
object, the functions are called in random order, immediately
after the object's event handler is called."
It's somewhat ambiguous. Functions are called in a random order. I know
it's the same with DOM listeners, but a better wording could have been
used. It also appears that functions added with attachEvent aren't event
handlers for the object and something else is, but what?
Finally, I like how references are called pointers in the MS docs.
--
Michael Winter
M.Winter@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)