Reputation: 9020
I'm trying to insert javascript in my document by another javascript
I have a code:
script = document.createElement('script');
script.type = 'text/javascript';
script.onreadystatechange = function () {
if (this.readyState == 'complete') proceed();
} //this for IE but it doesn't work even for IE8
script.onload = proceed; //this is for other browsers
so, how can I make it work for IE
Upvotes: 0
Views: 1232
Reputation: 178026
Can you try this to see if you ever get a complete
script.onreadystatechange = function () {
document.title=this.readyState + ' - ' + new Date();
if (this.readyState == 'complete') start();
}
Upvotes: 1
Reputation: 2914
I believe there is something missing in your code. Namely actually appending the created script tag to the document.
Something like:
var head = document.getElementsByTagName('head')[0];
head.appendChild(script);
After the lines of your script.
You can find this script hosted at http://ikanobori.jp/examples/loading-external-javascript/ where http://ikanobori.jp/examples/loading-external-javascript/one.js is the first file and http://ikanobori.jp/examples/loading-external-javascript/two.js is the dynamically loaded file.
I have verified this to work in Internet Explorer 8 but do not have lower versions available her.
Upvotes: 1