Skip to content

Instantly share code, notes, and snippets.

@dperini
Created August 23, 2011 19:28
Show Gist options
  • Save dperini/1166240 to your computer and use it in GitHub Desktop.
Save dperini/1166240 to your computer and use it in GitHub Desktop.
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