Mozilla/Firefox and Safari event phase and propagation bug

Click here to run the test.

What is going on here?

According to the W3C DOM specification, events should not fire on the target object in the capture phase. Event capture should only fire for ancestors of the event target. Mozilla/Firefox and Safari break this rule and fire it anyway. Even if it were correct to fire it, Mozilla/Firefox fires it at the wrong time - after firing the bubble phase listener on the same element. Bubble should never fire before capture on any element.

What can be done to workaround this bug?

The event handler can check if the event has misfired, and stop processing. Unfortunately, it is only possible to check if the currentTarget is also the target, as Mozilla says the eventPhase is 'AT_TARGET' without saying which phase is currently being processed. This will require you to use a different handler function for the capturing and bubbling phases:

function eventHandler(e) {
	if( e.target == e.currentTarget ) {
		return; //error - browsers should never activate this!
	}
	...
}

Reported?

Reported to Bugzilla as bug 235441.


Back to HowToCreate | Contact