开发者

Can't execute code from a freed script - IE6 IE7 IE8 IE9

I ran in开发者_JAVA百科to this problem today in IE6 (but is reproducible on all recent version of IE).

I noticed quite a few people run into this problem and I haven't seen a very practical way to fix this.

There seems to be some other solution floating about regarding the order of script tags and meta tags in the head of the HTML document. I haven't confirm this but here's a link anyway: What causes the error "Can't execute code from a freed script"

I also know the solution to this problem so I'm posting it below


First of all you need to locate the source of the message.

IE is known for it's abysmal error reporting but luckily IE9 seems somewhat capable. If this bug occurs in IE6, IE7 or IE8 it will also occur in IE9, so use IE9 to debug (for your sanity)

Open the webdeveloper console in IE9 (press F12) and run through the steps to produce this error.

IE9 should now give you a file and line indication on the console, yay!

What typically goes wrong is a callback that is executed after some delay, either by setTimeout or because of an Ajax request. If the window, document or frame the callback is defined in got unloaded then you will get this message when it tries to execute your callback function.

Seemingly other browsers ignore this problem, which is fine I guess. To make IE do the same just wrap the callback in a try-catch block (I don't know what the callback would evaluate to, I don't think it evaluates to undefined). If you want have more precise error handling or if you actually want to take action when this occurs you can probably do so and please make a post here because I'm curious as to what kind of use case would actually require this.


If you have page that uses several Frames, this error might be caused by objects initialized in one frame being used in some other frame after the initial frame was removed from the page.

When that happens, then depending on situation, you might want to:

  • Review your code looking for potential memory leaks
  • If those object represent some data you do actually want passed between frames, then consider using their stringified form instead.


The solution - be sure to place all META statements BEFORE any script statements.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜