javascript 无法从释放的脚本中执行代码 - IE6 IE7 IE8 IE9
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5812180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't execute code from a freed script - IE6 IE7 IE8 IE9
提问by Halcyon
I ran into this problem today in IE6 (but is reproducible on all recent version of IE).
我今天在 IE6 中遇到了这个问题(但在所有最新版本的 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"
关于 HTML 文档头部的脚本标签和元标签的顺序,似乎还有其他一些解决方案。我还没有确认这一点,但无论如何这里有一个链接: 是什么导致错误“无法从释放的脚本中执行代码”
I also know the solution to this problem so I'm posting it below
我也知道这个问题的解决方案,所以我把它贴在下面
回答by Halcyon
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)
IE 以其糟糕的错误报告而闻名,但幸运的是 IE9 似乎有点能力。如果这个bug出现在IE6、IE7或IE8中,它也会出现在IE9中,所以使用IE9进行调试(为了你的理智)
Open the webdeveloper console in IE9 (press F12) and run through the steps to produce this error.
在 IE9 中打开 webdeveloper 控制台(按 F12)并运行产生此错误的步骤。
IE9 should now give you a file and line indication on the console, yay!
IE9 现在应该在控制台上给你一个文件和行指示,是的!
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.
通常会出错的回调是在一些延迟后执行的,要么是通过 setTimeout 要么是因为 Ajax 请求。如果回调定义的窗口、文档或框架被卸载,那么当它尝试执行你的回调函数时你会收到这个消息。
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.
似乎其他浏览器忽略了这个问题,我想这很好。为了让 IE 做同样的事情,只需将回调包装在一个 try-catch 块中(我不知道回调会评估什么,我认为它不会评估为未定义)。如果您想要更精确的错误处理,或者如果您真的想在发生这种情况时采取行动,您可能可以这样做,请在此处发帖,因为我很好奇哪种用例实际上需要这样做。
回答by M. Prokhorov
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 doactually want passed between frames, then consider using their stringified form instead.
- 检查您的代码以查找潜在的内存泄漏
- 如果这些对象代表你的一些数据做其实是想帧之间通过,则可以考虑使用他们的字符串化的形式来代替。
回答by Mark Findlay
The solution - be sure to place all META statements BEFORE any script statements.
解决方案 - 确保将所有 META 语句放在任何脚本语句之前。