2

我有一个 html 页面,我在其中定义了一个全局App.vent主干事件对象。

var App = {};
App.vent = _.extend({}, Backbone.Events);

在该页面内,我有一个引用该App对象的 iframe。

App = parent.App;

iframe 页面内调用App.vent触发事件的代码工作正常。但是如果 iframe 的 src 发生变化,那么任何方法调用App.vent都会失败,IE 会给出一个

SCRIPT5011:无法从释放的脚本错误中执行代码。

任何解决方法?

4

1 回答 1

3

There is already a very good example of why this occurs in this following answered question:

What causes the error “Can't execute code from a freed script”</a>

In particular check out this answer by Sjoerd Visscher as it both outlines your problem and shows a workaround.

Lastly, it would be much better form to ensure that you keep track of your event binding and remove any bindings to functions that were contained in iframe content that no longer exist. This is a memory leak and good practice is to control these sorts of things.

于 2013-06-08T02:20:52.310 回答