Dan*_*Tao 3 javascript internet-explorer google-chrome javascript-injection labjs
我确信我不完全理解这个问题,但似乎我们在我的项目中看到IE9上的奇怪行为,不知何故与通过调用注入的JavaScript的无序执行有关document.write,例如:
document.write('<scr'+'ipt type="text/javascript" src="'+file1+'"></src'+'ipt>');
document.write('<scr'+'ipt type="text/javascript" src="'+file2+'"></src'+'ipt>');
document.write('<scr'+'ipt type="text/javascript" src="'+file3+'"></src'+'ipt>');
Run Code Online (Sandbox Code Playgroud)
我有限的谷歌研究表明,IE9将以与其他浏览器不同的顺序执行以这种方式注入的脚本(特别是Firefox和Chrome).有没有更好的方法来实现我们的目标,这将确保所有浏览器的执行顺序相同?
我把它拿回来了:我们并不关心所有浏览器,只关注Chrome和IE9.
我想你可以链接一个onload事件来启动另一个的负载:
var newJS= document.createElement('script');
newJS.onload=function() {alert("done")} //or call next load function
newJS.src="..."
document.body.appendChild(newJS)
Run Code Online (Sandbox Code Playgroud)