开发者

why is IE8 loading javascripts incompletely?

I'm running IE8 in normal mode (whatever it is when compatibility is NOT turned on) on WinXP. I'm doing maintenance on a rails app that was written a few years ago. Often when I load a page, and/or refresh a page, it reports different javascript errors. When I look at the errors in the Developer tool, it appears that a javascript file hasn't loaded completely. So th开发者_开发知识库e errors are frequently syntax related, such as '}' expected.


Trailing comma in object literal or array declaration? Some browsers accept this without error, IE does not.

// Trailing commas are bad
var someArray = [
    "thing",
    "last",
];
var someObject = {
    one: "thing",
    after: "another",
};

As galambalazs suggested in his comment, jslint will pick up problems like this for you.


Cntrl + F your javascript file and look for a rogue "return" statement.


I ran into this problem on older versions of IE. It was never reproducible in a test harness and left no trace in server logs, but consistently affected a very small percentage of IE 6 loads.

The solution was to have the embedding HTML file double check that the JS was loaded.

foo.js:

// do all the real work.

// As the last statement, set a variable indicating completion.
foo_js_fully_loaded = true;

foo.html:

<script src=foo.js></script>
<script>if (!foo_js_fully_loaded) { /* reload the page */ }</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜