Cross-browser Event Handling
I need a cross-browser function for registering event handlers and a (mostly) consistent handler experience. I don't need the full weight or functionality of a library such as jQue
Solution 1:
There's a problem on this line:
r = elem.attachEvent("on" + evt, func.call(elem, window.event));
This will execute func() immediately, instead of attaching it as a handler for the event. Instead, the return value of func() will be assigned to the event, which will throw an error if it's type isn't "function"
.
I can understand that you don't want to use a framework, but many (many) others have written cross-browser event handling snippets. John Resig has one version, Google for "javascript addEvent" for many more.
Post a Comment for "Cross-browser Event Handling"