gpt4 book ai didi

javascript - 如何修复 "An unbalanced tree was written using document.write() causing data from the network to be reparsed"?

转载 作者:行者123 更新时间:2023-11-28 12:28:47 26 4
gpt4 key购买 nike

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 when document.write() changes the tree builder state such that the speculative state after the </script> tag no longer holds when all the content inserted by document.write() has been parsed. However, only unusual uses of document.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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com