Skip to content

Instantly share code, notes, and snippets.

@frankitox
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankitox/8833877 to your computer and use it in GitHub Desktop.
Save frankitox/8833877 to your computer and use it in GitHub Desktop.
Cross-Browser event attach handler
// Crossbrowser event attacher.
var addEventListener = function (elem, evento, handler) {
console.assert(elem.addEventListener || elem.attachEvent, "Can't find an event handler.");
if (elem.addEventListener) {
elem.addEventListener(evento, function (e) {
if (handler.call(elem, e) === false)
e.preventDefault();
});
} else if (elem.attachEvent) {
elem.attachEvent('on' + evento, function (e) {
if (handler.call(elem, e) === false)
e.returnValue = false;
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment