Last active
August 29, 2015 14:15
-
-
Save davidklassen/6d44e4f9017071421706 to your computer and use it in GitHub Desktop.
Handle all DOM events
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
// 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