JS 错误:
An unbalanced tree was written using document.write() causing data from the network to be reparsed
<script type="text/javascript">
beginAnchor("javascript:popupManager.close()");
</script>
<img src="../images/icons/icon_cancel.gif" border="0" alt="" title="">
<script type="text/javascript">
endAnchor();
</script>
最佳答案
这不是错误,而是警告。它发生在 Firefox 4 及更高版本中。
来自MDN: Optimizing your pages for speculative parsing :
However, in Firefox 4 and later the HTML parser also runs the HTML tree construction algorithm speculatively. The upside is that when a speculation succeeds, there's no need to reparse the part of the incoming file that was already scanned for scripts, style sheets and images. The downside is that there's more work lost when the speculation fails.
[...]
Speculative tree building fails whendocument.write()
changes the tree builder state such that the speculative state after the</script>
tag no longer holds when all the content inserted bydocument.write()
has been parsed. However, only unusual uses ofdocument.write()
cause trouble. Here are the things to avoid:
[...]
Don't write unbalanced trees.<script>document.write("<div>");</script>
is bad.<script>document.write("<div></div>");</script>
is OK.
解决方案是将 HTML 编写在单个 <script>
中如果您关心性能损失,请阻止。如果您愿意,也可以忽略它。
关于javascript - 如何修复 "An unbalanced tree was written using document.write() causing data from the network to be reparsed"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24731079/