I try the code provided at https://stackoverflow.com/a/950146/151453 , and I successfully verified that I can load my t2.js
from t1.js
. However, t2.js
finish-loading callback works only for Chrome (v26), Firefox (v17), and IE10, but NOT for Microsoft IE8 (Windows 7) .
The symptom on IE8 is: The callback start_deco()
is never called.
How can I achieve the same result in IE8? Thank you.
==== Code below ====
t1.html :
<html>
<head></head>
<body>
Hello!
<script src="t1.js"></script>
</body>
</html>
t1.js :
// loadScript function provided by https://stackoverflow.com/a/950146/151453
function loadScript(url, callback)
{
// adding the script tag to the head as suggested before
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
// then bind the event to the callback function
// there are several events for cross browser compatibility
//script.onreadystatechange = callback; // chj: !!!
script.onload = callback;
// fire the loading
head.appendChild(script);
}
function start_deco()
{
alert('Done t2.js.');
loadScript('t3.js.');
}
loadScript('t2.js', start_deco) // wish to load jquery.js etc
t2.js :
console.log('Loading t2.js...')
t3.js :
console.log('Loading t3.js...')
============== UPDATE1 =================
On IE8, if I enable script.onreadystatechange = callback;
in loadScript()
, the alert box does pop up, however, calling loadScript('t3.js.');
fails with "Not implemented error" on that line so that t3.js fails to load. Image below: