简体   繁体   English

无法从释放的脚本执行代码 - IE6 IE7 IE8 IE9

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

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.关于 HTML 文档头部的脚本标签和元标签的顺序,似乎还有其他一些解决方案。 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. IE 以其糟糕的错误报告而闻名,但幸运的是 IE9 似乎有些能力。 If this bug occurs in IE6, IE7 or IE8 it will also occur in IE9, so use IE9 to debug (for your sanity)如果这个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.通常出现问题的是在一些延迟后执行的回调,无论是通过 setTimeout 还是由于 Ajax 请求。 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.如果 window、文档或框架中定义的回调被卸载,那么当它尝试执行您的回调 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).为了让 IE 做同样的事情,只需将回调包装在 try-catch 块中(我不知道回调将评估为什么,我认为它不会评估为未定义)。 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查看您的代码,寻找潜在的 memory 泄漏
  • If those object represent some data you do actually want passed between frames, then consider using their stringified form instead.如果这些 object 表示您确实希望在帧之间传递的一些数据,那么请考虑使用它们的字符串化形式。

The solution - be sure to place all META statements BEFORE any script statements.解决方案 - 确保将所有 META 语句放在任何脚本语句之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM