我正在尝试通过另一个JavaScript在我的文档中插入JavaScript
我有一个代码:
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
因此,如何使它适用于IE
最佳答案
我相信您的代码中缺少某些内容。即实际上将创建的脚本标签附加到文档。
就像是:
var head = document.getElementsByTagName('head')[0];
head.appendChild(script);
在脚本行之后。
您可以在http://ikanobori.jp/examples/loading-external-javascript/处找到此脚本,其中http://ikanobori.jp/examples/loading-external-javascript/one.js是第一个文件,而http://ikanobori.jp/examples/loading-external-javascript/two.js是动态加载的文件。
我已经验证了它可以在Internet Explorer 8中正常工作,但没有可用的较低版本。
关于javascript - 如何为IE设置onload事件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5806979/