IE8"HTML Parsing Error:Unable to modify the parent container element before the child element is closed"錯誤

來源:互聯網
上載者:User

標籤:blog   io   ar   os   sp   java   for   on   div   

一、IE8報下面錯誤,解決辦法:
網頁錯誤詳細資料
訊息: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
行: 0
字元: 0
代碼: 0
1、查看是否有未關閉的html標籤,比如<table>而沒有</table>
2、是否在頁面未載入完前js代碼操作了body裡的元素,將相關js代碼移到</body>後面
3、是否在代碼中添加了addthis分享js
4、是否IE8開啟了相容性檢視
(我的頁面出錯就是3、4兩個原因導致的)


二、之所以發生這樣的錯誤,是因為某些DOM操作發生在DOM樹載入完成之前,比如appendChild
就像下面的代碼:
<html>
<head>
</head>
<body>
<div>
<script type="text/javascript">
    alert(document.readyState);
    var oDiv = document.createElement("DIV");
    oDiv.innerHTML = ‘afish.cnblogs.com‘;
    document.body.appendChild(oDiv);
</script>
</div>
</body>
</html>
當解析到DIV時就開始在BODY上appendChild,而這個時候BODY是還沒有完全就緒的(It is not fully loaded),文檔結構仍在loading和interactive狀態之間,於是,便會得到上述錯誤。當然,該錯誤目前已確切知道的會存在於IE6和 IE7兩個版本中(低於IE6的未進行測試),在IE8中將會得到一個HTML解析錯誤:HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
1.要解決這個問題,可以進行document.readyState狀態判斷,當它為complete時再進行相應的操作,或者給script標籤加上defer屬性(該屬性在IE8中已不獲支援)。
2.或者在js中加入了 setTimeout("xxx()",1000);,使其獲得足夠的載入時間後執行目標(xxx)的function,於是問題得到解決。

IE8"HTML Parsing Error:Unable to modify the parent container element before the child element is closed"錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.