Created
July 19, 2012 17:08
-
-
Save podlipensky/3145383 to your computer and use it in GitHub Desktop.
Simple cross-browser event handling logic for rapid examples prototyping
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
(function(window){ | |
var doc = document.documentElement, | |
addListener, removeListener; | |
if (doc.addEventListener && doc.removeListener) { | |
addListener = function (element, eventName, handler) { | |
element.addEventListener(eventName, handler, false); | |
}; | |
removeListener = function (element, eventName, handler) { | |
element.removeEventListener(eventName, handler, false); | |
}; | |
} | |
else if (doc.attachEvent && doc.detachEvent) { | |
addListener = function (element, eventName, handler) { | |
element.attachEvent('on' + eventName, handler); | |
}; | |
removeListener = function (element, eventName, handler) { | |
element.detachEvent('on' + eventName, handler); | |
}; | |
} | |
else { | |
addListener = function (element, eventName, handler) { | |
element['on' + eventName] = handler; | |
}; | |
removeListener = function (element, eventName, handler) { | |
element['on' + eventName] = null; | |
}; | |
} | |
window.addListener = addListener; | |
window.removeListener = removeListener; | |
})(this) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment