Skip to content

Instantly share code, notes, and snippets.

@dperini
Created Aug 23, 2011
Embed
What would you like to do?
Feature testing browser support for 'load' events
<script type="text/javascript">
// 'load' events should be supported by every browser
// this was just an exercise to find a way to test it
var isLoadSupported = 'onload' in window, loadHandler = window.onload;
document.createElement('body').setAttribute('onload', 'return');
isLoadSupported = isLoadSupported || typeof window.onload == 'function';
window.onload = loadHandler;
window.addEventListener('DOMContentLoaded', function(e) {
alert(e.type + " - " + isLoadSupported);
}, false);
window.addEventListener('load', function(e) {
alert(e.type + " - " + isLoadSupported);
}, false);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment