Skip to content

Instantly share code, notes, and snippets.

@davidklassen
Last active August 29, 2015 14:15
Show Gist options
  • Save davidklassen/6d44e4f9017071421706 to your computer and use it in GitHub Desktop.
Save davidklassen/6d44e4f9017071421706 to your computer and use it in GitHub Desktop.
Handle all DOM events
// chrome
Object.keys(document)
.filter(function (i) {
return i.substring(0,2) == 'on' && (document[i] == null || typeof document[i] == 'function');
})
.map(function (e) {
return e.slice(2);
})
.forEach(function (eventName) {
document.addEventListener(eventName, function (event) {
console.log('[' + eventName + ']', event);
});
});
// firefox
[i for (i in document)]
.filter(function (i) {
return i.substring(0,2) == 'on' && (document[i] == null || typeof document[i] == 'function');
})
.map(function (e) {
return e.slice(2);
})
.forEach(function (eventName) {
document.addEventListener(eventName, function (event) {
console.log('[' + eventName + ']', event);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment