1

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
balupton
  • 47,113
  • 32
  • 131
  • 182

2 Answers2

2

You can only use fire for custom events.

Take a look at this question/answer. I think it solves your problem. It's certainly what we use.

Community
  • 1
  • 1
Nick
  • 2,418
  • 16
  • 20
1

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

Which allows a consistent API for custom and standard events.

balupton
  • 47,113
  • 32
  • 131
  • 182