I've got a script with a DOMContentLoaded
event handler—
document.addEventListener('DOMContentLoaded', function() {
console.log('Hi');
});
Which I'm loading asynchronously—
<script async src=script.js></script>
However, the event handler is never called. If I load it synchronously—
<script src=script.js></script>
It works fine.
(Even if I change the DOMContentLoaded
event to a load
event, it's never called.)
What gives? The event handler should be registered irrespective of how the script is loaded by the browser, no?
Edit: It doesn't work on Chrome 18.0.1025.11 beta but, with DOMContentLoaded
, it does on Firefox 11 beta (but with load
it doesn't). Go figure.
OH GREAT LORDS OF JAVASCRIPT AND THE DOM, PRAY SHOW THE ERROR OF MY WAYS!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…