问题描述
我确定我没有完全理解这个问题,但它似乎我们在我的项目上看到了IE9上的奇怪行为,它与JavaScript的乱序执行有关已通过调用注入到 document.write
,例如:
I am sure I don't fully understand this problem, but it seems that we are seeing strange behavior on IE9 on my project, somehow related to out-of-order execution of JavaScript that has been injected via calls to document.write
, e.g.:
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>');
我有限的Google研究表明,IE9将以与其他浏览器不同的顺序执行以此方式注入的脚本(特别是Firefox和Chrome)。有没有更好的方式来实现我们在这里的目标,这将确保所有浏览器执行相同的命令?
My limited Google research suggests that IE9 will execute scripts injected in this manner in a different order from other browsers (notably, Firefox and Chrome). Is there a better way to achieve what we're going for here, which will ensure the same execution order by all browsers?
我回顾一下:我们没有真的关心所有浏览器,只有Chrome和IE9。
I take that back: we don't really care about all browsers, just Chrome and IE9.
推荐答案
使用脚本加载器我写了一个:),它将标准化各种浏览器中所有不同的加载特性。和奖金:它不使用那个神奇的document.write()。 LABjs将允许您异步(并行)加载所有脚本,但要确保它们按正确的顺序执行。听起来基本上就是你想要的。
Use a script loader (like the one I wrote: LABjs), which will normalize all the different quirks of loading across the various browsers. And bonus: it doesn't use that god-awful document.write(). LABjs will let you load all your scripts asynchronously (in parallel), but make sure they execute in the proper order. Sounds like basically exactly what you want.
这篇关于有没有一个已知的解决方法,IE9的注入脚本标签的执行顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!