In my project, window.onload
is executed before the dynamic script is loaded in IE 8, 9.
I have following codes.
index.html
<DOCTYPE html>
<html>
<head>
<script>
var eScript = document.createElement('script');
eScript.type = 'text/javascript';
eScript.src = './script.js';
var eHead = document.querySelector('head');
eHead.appendChild(eScript);
window.onload = function() {
console.log('all resource is loaded');
}
</script>
</head>
<body>
</body>
</html>
script.js
console.log('[START] script.js');
and the console output is:
IE 8, 9
> all resource is loaded
> [START] script.js
IE 10, 11
[START] script.js
all resource is loaded
Question?
I know that window.onload will run after downloading all the resources needed for the page. IE 10, 11 work as expected, but IE 8, 9 behave incorrectly.
I need an event listener that will be called after all dynamic resources (like script.js) have been downloaded and run in IE 8 and 9. I would be grateful if there is such a way.
What should I do? Thank you.