發表新主題
隨機主題
上個主題
下個主題
|
優化 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 登入來發表迴響。若使用羊皮紙會員身份發表迴響則可獲得經驗值及虛擬金幣,用來參加羊皮紙推出的活動。
發表迴響
 
驗證字串