发表新主题
随机主题
上个主题
下个主题
|
优化 JS 程式

Avoiding losing tree builder output

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

几个需要避免的问题:

  • 不要使用造成不平均树的写法,例如∶<script>document.write("<div>");</script> 要写成 <script>document.write("<div></div>");</script>
  • 记得不要少写了结束符号,例如∶<script>document.write("<div></div");</script>
  • 不要在写入的字串中使用 \r ,例如<script>document.write("Hello World!\r");</script>,应该使用 \n 代替<script>document.write("Hello World!\n");</script>
  • Note that writing balanced tags may cause other tags to be inferred in a way that makes the write unbalanced. E.g. <script>document.write("<div></div>");</script> inside the head element will be interpreted as <script>document.write("</head><body><div></div>");</script> which is unbalanced.
  • Don't let the semicolon of a named character reference be the last thing that is written. Due to a bug in Firefox 4 though 10 (fixed in Firefox 11), <script>document.write("foo&nbsp;");</script> causes a speculation failure. However, <script>document.write("&nbsp;foo");</script> is OK.
  • TODO: document.write inside formatting elements.
  • 本文为转载文章 [原文]
  • 关键字 : script, write, document, 例如, unbalanced, state, inside, cause, builder, World, However, Hello, Firefox, 问题, 避免, 记得, 要写成, 结束符号, 应该使用, 少写
0 0
2012-01-12T10:06:00+0000


  • 当您未登入羊皮纸时,可以利用脸书 Facebook 登入来发表回响。若使用羊皮纸会员身份发表回响则可获得经验值及虚拟金币,用来参加羊皮纸推出的活动。
发表回响
 
验证字串