Monday, November 02, 2009

Prototype - Event.fire exception to be handled for IE

Prototype 1.6 has introduced Event.fire API that works pretty well in Firefox but experienced a problem in IE (7).

Exception was being thrown in Event.fire API that needed a special treat.

The highlighted workaround worked for me:
fire: function(element, eventName, memo) {
// ...
if (document.createEvent) {
element.dispatchEvent(event);
} else {
try{
element.fireEvent(event.eventType, event);
} catch(error) {
// Error: No such interface supported (IE)
element.fireEvent(event.eventType);
}
}
return event;
}
Example:
Event.fire('myhidden_element_id', 'custom:change');

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?