无法执行已释放脚本中的代码 [英] Can't execute code from a freed script
问题描述
我有一个需要在其他框架中覆盖的功能.另外,我需要从重写中调用原始函数.为此,我正在使用以下内容:
I have a function that in a different frame that I need to override. In addition, I need to call the original function from within my override. To do so, I'm using the following:
myFrame.SomeFunction = (function () {
var originalSomeFunction = myFrame.SomeFunction;
return function(arg1, arg2, arg3) {
alert('In override!');
originalSomeFunction(arg1, arg2, arg3);
};
})();
执行此代码时,显示无法从已释放的脚本执行代码".
When I execute this code, I get "Can't execute code from a freed script".
有什么想法吗?有一个更好的方法吗?在IE 6、7、8和9中进行测试.
Thoughts? Is there a better way to do this? Testing in IE 6,7,8 and 9.
推荐答案
我想出了解决方案.
基本上,您可以获取我之前发布的所有代码,并使用eval()函数在目标框架的上下文中执行该代码.所以...
Basically, you take all of the code I previously posted, and the execute it from within the context of the target frame using the eval() function. So...
myFrame.eval("SomeFunction = (function () {var originalSomeFunction = SomeFunction; return function (arg1, arg2, arg2) {alert('Inside override!'); originalSomeFunction(arg1, arg2, arg3);};})();");
因为代码现在位于目标框架之内,所以它不会超出范围,并且我们也不会再收到已释放"错误.
Because the code is now within the target frame, it doesn't go out of scope, and we don't get the "freed" error anymore.
这篇关于无法执行已释放脚本中的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!