使用 document.write()
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用 document.write()
可讓網頁內容延遲數十秒顯示,對連線緩慢的使用者而言特別有問題。因此,Chrome 在許多情況下會封鎖 document.write()
的執行作業,這表示您無法依賴。
在 Chrome 開發人員工具控制台中使用 document.write()
時,系統會顯示以下訊息:
[Violation] Avoid using document.write().
您會在 Firefox 開發人員工具控制台中看到以下訊息:
An unbalanced tree was written using document.write() causing
data from the network to be reparsed.
Lighthouse document.write()
稽核失敗
Lighthouse 標記會標記未遭到 Chrome 封鎖的 document.write()
呼叫:
在最有問題的用途中,Chrome 會封鎖對 document.write()
的呼叫,或根據使用者的連線速度發出主控台警告。無論採用哪種方式,受影響的呼叫都會顯示在開發人員工具控制台中。
詳情請參閱 Google 的反對 document.write()
文章。
Lighthouse 會回報所有剩餘的 document.write()
呼叫,因為無論用途為何,效能都會對效能產生負面影響,而且還有更好的替代方案。
建議不要使用 document.write()
移除程式碼中所有 document.write()
的用途。如果將用於插入第三方指令碼,請嘗試改用非同步載入功能。
如果第三方程式碼使用 document.write()
,請要求供應商支援非同步載入。
資源
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2019-05-02 (世界標準時間)。
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"缺少我需要的資訊"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"過於複雜/步驟過多"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"過時"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻譯問題"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"示例/程式碼問題"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"容易理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"確實解決了我的問題"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]
{"lastModified": "\u4e0a\u6b21\u66f4\u65b0\u6642\u9593\uff1a2019-05-02 (\u4e16\u754c\u6a19\u6e96\u6642\u9593)\u3002"}
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2019-05-02 (世界標準時間)。"],[],[]]