Created
June 15, 2011 15:39
-
-
Save olooney/1027365 to your computer and use it in GitHub Desktop.
cross-browser event listeners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// observable is a DOM node, document, window, etc. | |
// eventName is the string event name, say "load" or "click" | |
// handler is the callback function. | |
function addEventListener(observable, eventName, handler) { | |
if ( observable.addEventListener ) { | |
observable.addEventListener(eventName, handler, false); | |
} else if ( observable.attachEvent ) { | |
observable.attachEvent("on" + eventName, handler); | |
} else { | |
// error handling? | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment