开发者

Binding and triggering native and custom events in Prototype

开发者 https://www.devze.com 2023-02-06 16:55 出处:网络
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

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 alr开发者_开发百科eady tried with no luck:

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

Any help would be appreciated.


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.


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

Which allows a consistent API for custom and standard events.

0

精彩评论

暂无评论...
验证码 换一张
取 消