Wednesday, July 14, 2010

Internet Explorer sanitizes events between nodes

Events are hard in IE. That is just a fact.

I'm not here to gripe about how IE's event object doesn't adhere to standards, nor offers alternatives. Really, I'm not. This is actually a surprising discovery that has less to do with the standard IE/MS diatribe, and more to do with a unique aspect of their event object.

Of all it's properties, the IE event object allows you to edit two: returnValue and cancelBubble. The returnValue property may be set to anything, while cancelBubble is converted to the boolean equivalent of whatever you assign.

You may add arbitrary properties to the event object, via a handler function. (As with w3c browsers, be careful not to cause an exception by writing to a read-only property.) However, you may not prototype the event's constructor in IE (it doesn't have one). Nor does IE implement the ever-popular hasOwnProperty() method. (Why? That's another post, let alone blog.)

Now after mangling an event object sufficiently (and within the aforementioned limits), how should that object look when it bubbles to the next node in the DOM? Unfortunately, with IE, it will be the same way it began in the previous one. Only the returnValue will retain the previously assigned value. (So would the cancelBubble property, but that doesn't matter since it wouldn't reach the next node anyway.) This behavior is observed in IE 6 thru 8.

IE either sanitizes the event object between nodes, or provides a new one altogether. There is no way I can tell which from looking at the object, alone. But recalling that, causes me to gripe about how the object doesn't have a standard timestamp property, or an equivalent native means to uniquely identify one event object from the next...

Mind you, this does not mean handler functions cannot pass arbitrary properties amongst themselves. The "sanitization" IE does is between nodes (or what an event bubbles through), not the numerous handler functions listening to one.

I might post a demo for this, but it's a tad complicated to prove a negative. Anyway, I discovered this while coding recently, and it blew chunks. Hope my experience helps!


No comments:

Post a Comment