Javascript 错误:尝试在已清除的范围内运行 compile-and-go 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5433415/
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
Error: Attempt to run compile-and-go script on a cleared scope
提问by nickf
Since upgrading to Firefox 4.0, I've noticed that I'm occasionally getting an error in the console stating:
升级到 Firefox 4.0 后,我注意到我偶尔会在控制台中收到一条错误消息:
attempt to run compile-and-go script on a cleared scope
尝试在清除的范围内运行 compile-and-go 脚本
The only information I can find about this on the net currently is on the mozilla groups forum, where it is suggested that it's something to do with session restoring. In my case, though I haven't been able to reliably reproduce the error, it happens at any time, not just after a restore.
我目前在网上能找到的关于此的唯一信息是在mozilla 组论坛上,建议它与会话恢复有关。就我而言,虽然我无法可靠地重现该错误,但它随时都会发生,而不仅仅是在恢复之后。
What's the deal? How do I stop the error?
这是怎么回事?如何停止错误?
回答by jakub.g
For me (Firefox 11, Firebug 1.9.1) it happens sometimes after I refresh the page (either F5 or CTRL+F5) while debugger is paused on a breakpoint.
对我来说(Firefox 11,Firebug 1.9.1)它有时会在我刷新页面(F5 或 CTRL+F5)而调试器在断点上暂停时发生。
The solution seems to be to continue the execution of the script, and refresh the page only when Firebug is notpaused.
解决办法好像是继续执行脚本,只在Firebug没有暂停时刷新页面。
回答by Nowaker
In my case, it was document.write
method causing the problem on Firefox 4, 5, 6 on Windows. Linux versions are unaffected. What I had to do is to overwrite document.write
method.
就我而言,它是document.write
导致 Windows 上 Firefox 4、5、6 出现问题的方法。Linux 版本不受影响。我必须做的是覆盖document.write
方法。
I aware that document.write
shouldn't be used these days, but deployJava.js
, a standard Java Applet deployment script written by Sun/Oracle, is using it. Google is using it in Google AdSense ads. document.write
is everywhere.
我知道现在document.write
不应该使用它,但是deployJava.js
由 Sun/Oracle 编写的标准 Java Applet 部署脚本正在使用它。Google 正在 Google AdSense 广告中使用它。document.write
无处不在。
<script>
var documentWriteOutput = '';
var got = document.write;
document.write = function(arg) { documentWriteOutput += arg; }
</script>
<script src="badScriptThatIsUsingDocumentWrite.js"></script>
<script>
runBadScriptThatIsUsingDocumentWrite();
document.write = got;
// Do whatever you want with the documentWriteOutput
// e.g. $('#somewhere').html(documentWriteOutput);
</script>
I hope this helps. However, I saw lots of "solutions" on the Internet that didn't work for me. It may mean that "Attempt to run compile-and-go script on a cleared scope"is a Firefox JavaScript engine problem/bug.
我希望这有帮助。但是,我在互联网上看到了很多对我不起作用的“解决方案”。这可能意味着“尝试在清除的范围内运行编译并运行脚本”是 Firefox JavaScript 引擎问题/错误。
回答by Nate C-K
I've noticed that this error can happen if you write to the document with document.write after the document has completed loading (e.g. in a function called from JQuery's $(document).ready() method). When this happens, it seems that Firefox discards the old document and writes a new one. I don't know if this is new behavior or not. It seems that when you try to operate on the old document, e.g. with JQuery selectors, you get this error. For me, fixing the script in question to not call document.write after the document had loaded fixed the error.
我注意到如果在文档加载完成后使用 document.write 写入文档(例如,在从 JQuery 的 $(document).ready() 方法调用的函数中),则可能会发生此错误。发生这种情况时,似乎 Firefox 会丢弃旧文档并编写新文档。我不知道这是否是新行为。似乎当您尝试对旧文档进行操作时,例如使用 JQuery 选择器,您会收到此错误。对我来说,修复有问题的脚本以在文档加载后不调用 document.write 修复了错误。
回答by Liam
I have noticed that if I disable the cache, I no longer get this error in the console.
我注意到,如果禁用缓存,控制台中将不再出现此错误。
回答by Wolfgang
The error doesn't occur if Firebug (in my case 1.8) is disabled.
如果 Firebug(在我的情况下为 1.8)被禁用,则不会发生该错误。
回答by Eneas Gesing
Check your code for duplicated meta cache-control and remove one of them:
检查您的代码是否存在重复的元缓存控制并删除其中之一:
<meta http-equiv="cache-control" content="no-cache" />
回答by user1046787
i had this problem too but I did a clean re-installation of FireFox.
我也有这个问题,但我重新安装了 FireFox。
after that the error was gone.
之后错误消失了。
回答by kuldar
I got this error when I tried adding events on elements appended from a same domain iframe. Added clone() and errors stopped.
当我尝试在从同一域 iframe 附加的元素上添加事件时出现此错误。添加了 clone() 并停止了错误。
回答by Terry Boswell
It has nothing to do with firebug. The reason it "goes away" when firebug is disabled is that you are no longer seeing the exception. The cause of this is having an handler attached to an event that is now null but not properly cleaned up. You need to make sure that handler is properly disposed of, otherwise the event still fires the reference to the handler.
它与萤火虫无关。当萤火虫被禁用时它“消失”的原因是您不再看到异常。造成这种情况的原因是有一个处理程序附加到一个现在为空但未正确清理的事件。您需要确保正确处理处理程序,否则事件仍会触发对处理程序的引用。
回答by daniel barucha
It is: menu Firebug -> Console -> Show Chrome Errors
它是:菜单 Firebug -> 控制台 -> 显示 Chrome 错误
switch off, end of story ;)
关掉,故事结束;)