Search code examples
javascriptevent-handlingprototypejsdom-eventscustom-events

Binding and triggering native and custom events in Prototype


I'm having a bit of issue with events in prototype.

I'm trying to bind and fire the native events: onhashchange, and onpopstate. As well as my custom events: statechange and anchorchange. All these events are for the window element.

Here's the code I've already tried with no luck:

Element.observe(window,eventName,eventHandler);
Element.fire(window,eventName);

Any help would be appreciated.


Solution

  • I ended up coming up with this: https://gist.github.com/796871

    Which allows a consistent API for custom and standard events.