Skip to content

Instantly share code, notes, and snippets.

@ando19721226
Created August 9, 2012 00:10
Show Gist options
  • Save ando19721226/3299880 to your computer and use it in GitHub Desktop.
Save ando19721226/3299880 to your computer and use it in GitHub Desktop.
addListener
var addListener = (function (window) {
if (window.addEventListener) {
return function (el, type, fn) {
el.addEventListener(type, fn, false);
};
}
if (window.attachEvent) {
return function (el, type, fn) {
var f = function () {
fn.call(el, window.event);
};
el.attachEvent('on' + type, f);
};
}
return function (el, type, fn) {
el['on' + type] = fn;
};
}(window));
@ando19721226
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment